Skip to content

Commit

Permalink
fix(select-hook): use the correct form target
Browse files Browse the repository at this point in the history
  • Loading branch information
Apatil15 committed Aug 13, 2021
1 parent 1fd081a commit a2b432b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/react/src/utilities/select/hook.tsx
Expand Up @@ -38,19 +38,22 @@ export const useSelect = (
if (!selected.includes(value)) select(value);
else if (multiple) deselect(value);
},
formChangeHandler: ({ target }) => {
if (!('value' in target) || !('checked' in target)) {
formChangeHandler: ({ currentTarget, target }) => {
const { checked, value } = (('value' in currentTarget) && ('checked' in currentTarget))
? currentTarget as HTMLInputElement
: target as HTMLInputElement;
if (checked !== undefined || !value) {
if (checked) {
select(value);
} else {
deselect(value);
}
} else {
throw new Error(
'formChangeHandler is being attached to an invalid element. '
+ 'Attach it to an <input type="checkbox|radio"> or a <fieldset>.',
);
}
const { checked, value } = target;
if (checked) {
select(value);
} else {
deselect(value);
}
},
};
};
Expand Down

0 comments on commit a2b432b

Please sign in to comment.