Skip to content

Commit

Permalink
fix(Select): html respects value passed (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
billgil authored Mar 28, 2023
1 parent eae77c6 commit 8d3ce22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-jobs-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@web3uikit/core': patch
---

fix(Select): html respects value passed
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ const TraditionalSelect: React.FC<ISelectProps> = ({
width = '200px',
...props
}: ISelectProps) => {
const [currentValue, setCurrentValue] = useState<
string | number | string[]
>();
const [currentValue, setCurrentValue] = useState('');

useEffect(() => {
if (!value) return;
setCurrentValue(value);
const dayObject = options.find((item) => item.label === value);
typeof dayObject?.label === 'string' &&
setCurrentValue(dayObject?.label);
}, [value]);

useEffect(() => {
if (Number(defaultOptionIndex) < 0) return;
if (Number(defaultOptionIndex) > options.length) return;

setCurrentValue(options[Number(defaultOptionIndex)]?.label || '');
const value = options[Number(defaultOptionIndex)]?.label;
typeof value === 'string' && setCurrentValue(value);
}, [defaultOptionIndex]);

const handleChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
Expand Down

0 comments on commit 8d3ce22

Please sign in to comment.