-
Notifications
You must be signed in to change notification settings - Fork 233
fix(menu): MenuItem focus stealing from input elements on mouseover #5732
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: main
Are you sure you want to change the base?
Changes from all commits
2caf026
c8e94d5
05d2b47
b038e1b
14fad8d
7893ce0
8766fb4
fc347e3
0705dba
f1dddc8
e36b58b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@spectrum-web-components/menu': minor | ||
--- | ||
|
||
**Fixed** MenuItem focus stealing from input elements on mouseover by enhanceing MenuItem's `handleMouseover` method to detect when an input element currently has focus and prevent stealing focus in those cases. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -28,6 +28,11 @@ import '@spectrum-web-components/icons-workflow/icons/sp-icon-export.js'; | |||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-folder-open.js'; | ||||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-share.js'; | ||||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-show-menu.js'; | ||||||
import '@spectrum-web-components/search/sp-search.js'; | ||||||
import '@spectrum-web-components/textfield/sp-textfield.js'; | ||||||
import '@spectrum-web-components/number-field/sp-number-field.js'; | ||||||
import '@spectrum-web-components/combobox/sp-combobox.js'; | ||||||
import '@spectrum-web-components/color-field/sp-color-field.js'; | ||||||
|
||||||
export default { | ||||||
component: 'sp-menu', | ||||||
|
@@ -484,3 +489,105 @@ export const dynamicRemoval = (): TemplateResult => { | |||||
</sp-menu> | ||||||
`; | ||||||
}; | ||||||
|
||||||
export const InputsWithMenu = (): TemplateResult => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a great test case but I don't think we need a new story for it. If you wanted to replicate the behavior in a story, we could probably use the play functionality. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's already a comprehensive test coverage for the focus behavior in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My main thought with not adding this as a story is that it's a lot of manual instructions for the viewer of the page to complete to get the experience you're demonstrating. Maybe we defer adding any new stories until we have a chance to talk about Storybook docs more as a team? |
||||||
return html` | ||||||
<div style="padding: 20px; max-width: 600px;"> | ||||||
<h3>Input Focus Demo</h3> | ||||||
<p> | ||||||
Try typing in any input field below, then hover over the menu | ||||||
items. The input should maintain focus and not be interrupted. | ||||||
This demonstrates the fix for focus stealing from all supported | ||||||
input types. | ||||||
</p> | ||||||
|
||||||
<div | ||||||
style="display: grid; gap: 16px; grid-template-columns: 1fr 1fr; margin-bottom: 20px;" | ||||||
> | ||||||
<!-- Search Input --> | ||||||
<div> | ||||||
<label for="demo-search">Search:</label> | ||||||
<sp-search | ||||||
id="demo-search" | ||||||
placeholder="Search input..." | ||||||
style="width: 100%; margin-top: 8px;" | ||||||
></sp-search> | ||||||
</div> | ||||||
|
||||||
<!-- Textfield Input --> | ||||||
<div> | ||||||
<label for="demo-textfield">Textfield:</label> | ||||||
<sp-textfield | ||||||
id="demo-textfield" | ||||||
placeholder="Textfield input..." | ||||||
style="width: 100%; margin-top: 8px;" | ||||||
></sp-textfield> | ||||||
</div> | ||||||
|
||||||
<!-- Number Field Input --> | ||||||
<div> | ||||||
<label for="demo-number">Number Field:</label> | ||||||
<sp-number-field | ||||||
id="demo-number" | ||||||
placeholder="Number input..." | ||||||
style="width: 100%; margin-top: 8px;" | ||||||
></sp-number-field> | ||||||
</div> | ||||||
|
||||||
<!-- Combobox Input --> | ||||||
<div> | ||||||
<label for="demo-combobox">Combobox:</label> | ||||||
<sp-combobox | ||||||
id="demo-combobox" | ||||||
placeholder="Combobox input..." | ||||||
style="width: 100%; margin-top: 8px;" | ||||||
></sp-combobox> | ||||||
</div> | ||||||
|
||||||
<!-- Color Field Input --> | ||||||
<div> | ||||||
<label for="demo-color">Color Field:</label> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Minor nit: try to use sentence case headings in our demos to reinforce the design system content standards where possible! |
||||||
<sp-color-field | ||||||
id="demo-color" | ||||||
placeholder="Color input..." | ||||||
style="width: 100%; margin-top: 8px;" | ||||||
></sp-color-field> | ||||||
</div> | ||||||
|
||||||
<!-- Native Input --> | ||||||
<div> | ||||||
<label for="demo-native">Native Input:</label> | ||||||
<input | ||||||
id="demo-native" | ||||||
placeholder="Native input..." | ||||||
style="width: 100%; margin-top: 8px; padding: 8px; border: 1px solid #ccc; border-radius: 4px;" | ||||||
/> | ||||||
</div> | ||||||
</div> | ||||||
|
||||||
<sp-popover open> | ||||||
<sp-menu> | ||||||
<sp-menu-item>Search Results</sp-menu-item> | ||||||
<sp-menu-item>Recent Searches</sp-menu-item> | ||||||
<sp-menu-item>Saved Searches</sp-menu-item> | ||||||
<sp-menu-item>Advanced Search</sp-menu-item> | ||||||
<sp-menu-item>Search Settings</sp-menu-item> | ||||||
<sp-menu-item>Clear History</sp-menu-item> | ||||||
</sp-menu> | ||||||
</sp-popover> | ||||||
</div> | ||||||
`; | ||||||
}; | ||||||
|
||||||
InputsWithMenu.parameters = { | ||||||
tags: ['!dev'], | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||||||
}; | ||||||
|
||||||
InputsWithMenu.swc_vrt = { | ||||||
skip: true, | ||||||
}; | ||||||
|
||||||
InputsWithMenu.parameters = { | ||||||
// Disables Chromatic's snapshotting on a global level | ||||||
chromatic: { disableSnapshot: true }, | ||||||
}; |
Uh oh!
There was an error while loading. Please reload this page.