Skip to content

Commit

Permalink
fix: removed the imperative selector as it is not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
mHuzefa committed Mar 8, 2024
1 parent 0889cb5 commit 397ac89
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions packages/react/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,6 @@ const Select = React.forwardRef(function Select(
ariaProps['aria-describedby'] = helper ? helperId : undefined;
}

const selectDefaultTitle = (defaultValue) => {
const selectElement = document.getElementById(
id
) as HTMLSelectElement | null;
if (defaultValue) {
const defaultOption: HTMLOptionElement | null | undefined =
selectElement?.querySelector(`option[value=${defaultValue}]`);
setTitle(defaultOption?.text || '');
} else {
setTitle(
selectElement?.options[selectElement?.selectedIndex]?.text || ''
);
}
};
const handleFocus = (evt) => {
setIsFocused(evt.type === 'focus' ? true : false);
};
Expand Down Expand Up @@ -273,7 +259,10 @@ const Select = React.forwardRef(function Select(
});
}
useEffect(() => {
selectDefaultTitle(defaultValue);
const selectElement = document.getElementById(
id
) as HTMLSelectElement | null;
setTitle(selectElement?.options[selectElement?.selectedIndex]?.text || '');
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down

0 comments on commit 397ac89

Please sign in to comment.