Update manualy the input invalid property

This commit is contained in:
Arnaud 2025-03-31 20:41:09 +02:00
parent 579ab4fbed
commit 52c659b9f3
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
3 changed files with 10 additions and 3 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@codex-storage/marketplace-ui-components", "name": "@codex-storage/marketplace-ui-components",
"version": "0.0.51", "version": "0.0.52",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@codex-storage/marketplace-ui-components", "name": "@codex-storage/marketplace-ui-components",
"version": "0.0.51", "version": "0.0.52",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@codex-storage/sdk-js": "https://github.com/codex-storage/codex-js#feat/support-basic-auth", "@codex-storage/sdk-js": "https://github.com/codex-storage/codex-js#feat/support-basic-auth",

View File

@ -5,7 +5,7 @@
"type": "git", "type": "git",
"url": "https://github.com/codex-storage/codex-marketplace-ui-components" "url": "https://github.com/codex-storage/codex-marketplace-ui-components"
}, },
"version": "0.0.51", "version": "0.0.52",
"type": "module", "type": "module",
"scripts": { "scripts": {
"prepack": "npm run build", "prepack": "npm run build",

View File

@ -3,6 +3,7 @@ import {
ComponentType, ComponentType,
forwardRef, forwardRef,
InputHTMLAttributes, InputHTMLAttributes,
useEffect,
useState, useState,
} from "react"; } from "react";
import { attributes } from "../utils/attributes"; import { attributes } from "../utils/attributes";
@ -64,6 +65,12 @@ export const Input = forwardRef<HTMLInputElement, Props>(
) => { ) => {
const [invalid, setInvalid] = useState(isInvalid); const [invalid, setInvalid] = useState(isInvalid);
useEffect(() => {
if (mode === "manual") {
setInvalid(isInvalid);
}
}, [mode, isInvalid]);
const onInternalChange = (e: ChangeEvent<HTMLInputElement>) => { const onInternalChange = (e: ChangeEvent<HTMLInputElement>) => {
if (mode === "auto") { if (mode === "auto") {
setInvalid(e.currentTarget.checkValidity() !== true); setInvalid(e.currentTarget.checkValidity() !== true);