-
Notifications
You must be signed in to change notification settings - Fork 235
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
Changes from 7 commits
2caf026
c8e94d5
05d2b47
b038e1b
14fad8d
7893ce0
8766fb4
fc347e3
0705dba
f1dddc8
e36b58b
c401489
b768abc
1e3d057
74f9dfc
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,89 @@ 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> | ||
Rajdeepc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <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> | ||
| `; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * Copyright 2025 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * Regular expression pattern to match Spectrum Web Components input elements. | ||
| * Used to identify components that should maintain focus during menu interactions. | ||
| */ | ||
| export const INPUT_COMPONENT_PATTERN = | ||
|
||
| /^(SP-SEARCH|SP-TEXTFIELD|SP-NUMBER-FIELD|SP-COMBOBOX|SP-COLOR-FIELD)$/; | ||
Rajdeepc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Array of input component tag names for easier iteration and maintenance. | ||
| */ | ||
| export const INPUT_COMPONENT_TAGS = [ | ||
| 'SP-SEARCH', | ||
| 'SP-TEXTFIELD', | ||
| 'SP-NUMBER-FIELD', | ||
| 'SP-COMBOBOX', | ||
| 'SP-COLOR-FIELD', | ||
| ] as const; | ||
Uh oh!
There was an error while loading. Please reload this page.