Skip to content

Commit

Permalink
fix: Fixed input controlled value (#184)
Browse files Browse the repository at this point in the history
* fix: fix input controlled value

Signed-off-by: yazhou <[email protected]>

* chore: update version

Signed-off-by: yazhou <[email protected]>

---------

Signed-off-by: yazhou <[email protected]>
  • Loading branch information
yazhouio authored Jan 18, 2024
1 parent d0c82e3 commit 44954c7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-countries-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kubed/components': patch
---

fix: Fixed input controlled value
31 changes: 30 additions & 1 deletion packages/components/src/Input/Input.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,36 @@ export default {
component: Input,
};

export const Basic = () => <Input placeholder="please input some text" width={360} />;
export const Basic = () => {
return <Input placeholder="please input some text" width={360} onChange={console.log} />;
};

export const Controlled = () => {
const [value, setValue] = React.useState<undefined | string>('');

return (
<div>
<Input
placeholder="please input some text"
width={360}
value={value}
onChange={(e) => {
setValue(e.target.value.slice(0, 6));
}}
/>
<p>
<button
type="button"
onClick={() => {
setValue(undefined);
}}
>
clean
</button>
</p>
</div>
);
};

const suffix = (
<Tooltip content="点击选择容器镜像">
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const Input = forwardRef<InputProps, 'input'>(
disabled={disabled}
readOnly={readOnly}
{...rest}
value={fixControlledValue(selfValue)}
value={typeof value !== 'undefined' ? value : fixControlledValue(selfValue)}
onChange={handleChange}
onFocus={handleFocus}
onBlur={handleBlur}
Expand Down

0 comments on commit 44954c7

Please sign in to comment.