-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[base-ui][useSelect] onChange not working when activated through keyboard (Enter or Space key press) #41234
Comments
@smellai I can reproduce the issue in your sandbox, but I don't think it's an issue with Base UI I tested this keyboard interaction using the Controlled Select demo in the docs, and also the hook demo but converted to controlled mode: https://stackblitz.com/edit/mcve-react-base-ui-fd26fm?file=src%2FApp.tsx - both work as expected! |
so the issue is with the |
@smellai You're right ~ refs should be passed to the option through the hook instead of directly: const CountryOption = memo(({ option }: CountryOptionProps) => {
const optionRef = useRef<HTMLLIElement>(null);
const { getRootProps, highlighted } = useOption({
value: option.value,
label: option.label,
disabled: false,
rootRef: optionRef, // <------------------
});
const countryCallingCode = useMemo(
() => getCountryCallingCode(option.value),
[option.value]
);
return (
<li
{...getRootProps()} // <--- custom ref is here
className={classNames('option', { ['highlighted']: highlighted })}
>
<span>{option.label}</span>
<span>+{countryCallingCode}</span>
</li>
);
}); Demo: https://stackblitz.com/edit/stackblitz-starters-2pd8ej?file=src%2FApp.tsx |
👋 Thanks for using MUI Core! We use GitHub issues exclusively as a bug and feature requests tracker, however, For support, please check out https://mui.com/getting-started/support/. Thanks! If you have a question on Stack Overflow, you are welcome to link to it here, it might help others. |
Thanks! |
Steps to reproduce
Link to live example: https://stackblitz.com/edit/stackblitz-starters-gnadul?file=src%2FApp.tsx
Steps:
Current behavior
it works as expected with keyboard interaction on version 5.0.0-beta.25, buggy in version 5.0.0-beta.37
it works as expected with mouse click on latest.
Expected behavior
both mouse and keyboard interactions work as they were working in previous versions
Context
might be related to what discussed already in another issue #40486 (comment)
Your environment
npx @mui/envinfo
browser: Chrome
Search keywords: keyboard select combobox useSelect base
The text was updated successfully, but these errors were encountered: