[select] Allow spacebar to select elements#48615
Conversation
Deploy previewhttps://deploy-preview-48615--material-ui.netlify.app/ Bundle size
Check out the code infra dashboard for more information about this PR. |
There was a problem hiding this comment.
Pull request overview
Restores keyboard interaction for Select so pressing the Space key while an option is focused selects that option (bringing back the behavior from the previously reverted PR).
Changes:
- Refactors the internal “clone event + redefine target” logic into a shared
clonedOnChangehelper. - Adds an option-level
onKeyDownhandler to select/close on Space. - Adds a regression test covering Space-to-select.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/mui-material/src/Select/SelectInput.js | Adds shared clonedOnChange helper and implements Space key handling on options. |
| packages/mui-material/src/Select/Select.test.js | Adds a regression test asserting Space selects an option. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ebeec2b to
d9f50a3
Compare
|
@mj12albert @mnajdova updated the implementation and kept the key down handler, but now I'm triggering I can't really do it like in the button base since we already have a preventDefault in keyUp for a close-after-open fix. if (event.key === SPACE) {
// otherwise our MenuItems dispatches a click event
// it's not behavior of the native <option> and causes
// the select to close immediately since we open on space keydown
event.preventDefault();
} |
Reuse
handleItemClickin the item key down handler for space bar.Fixes #43874