You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem:kbdHandlers is created once at module load time by calling keyboardHandlers(), which closes over a single pressed flag. Every ListItemButton on the page shares that flag. If the user presses Space/Enter on one gallery item and releases on another (or after focus moves), pressed will be stale and the action will either fire incorrectly or silently skip. This was pre-existing, but the PR is fixing keyboard-handling correctness — the singleton makes the new ownership semantics unreliable across instances.
Fix: Create handlers per-instance:
exportfunctionListItemButton(props: Omit<JSX.IntrinsicElements["div"],"ref">): ReactElement{const[handlers]=useState(keyboardHandlers);// stable, called once per mountreturn(<div{...props}{...handlers}className={classNames("widget-gallery-item-button",props.className)}role="button"/>);}
🔶 Medium — No unit tests for the new ownership check (nested-element case)
Problem: Every existing test fires events directly on div[role="listitem"], so event.target === event.currentTarget is always true — the new isOwn guard is never exercised in the failing path. A regression (dropping the guard) would not be caught.
Fix: Add a bubbled-event case:
test("does NOT execute action when Space is pressed on a nested input",async()=>{constonExecuteAction=jest.fn();const[item]=objectItems(1);constprops=eventSwitch<EventEntryContext,HTMLDivElement>(()=>({ item,selectionType: "None",selectionMode: "clear",clickTrigger: "single"}),[...createActionHandlers(onExecuteAction)]);const{ user }=setup(<divrole="listitem"tabIndex={0}{...props}><inputdata-testid="nested-input"/></div>);awaituser.click(screen.getByTestId("nested-input"));awaituser.keyboard("[Space]");expect(onExecuteAction).toHaveBeenCalledTimes(0);});
A parallel test should cover ListItemButton — assert event.preventDefault is NOT called when the event bubbles from a child element.
File:packages/shared/widget-plugin-grid/src/selection/keyboard.ts line 14
Note:isSelectOneTrigger is used by both gallery-web and datagrid-web. Adding the isOwn check means that in a datagrid, pressing Shift+Space while focus is on a nested child within a row will no longer toggle row selection. This is likely correct behaviour, but it is a behavioural change in datagrid-web not mentioned in the PR description. Confirm this is intentional.
Positives
The isOwn check is placed in the filter of canExecOnSpaceOrEnter rather than inside the handler, so the pressed state in onSpaceOrEnter is never dirtied by bubbled events — correct design.
preventAndStop in ListItemButton.onKeyDown is correctly gated by isOwn before setting pressed, preventing onKeyUp from firing for an event whose keydown was on a nested element.
CHANGELOG entry is user-facing, describes before/after behaviour, and uses correct Keep a Changelog format.
Archived spec artifacts include design rationale documenting the currentTarget === target pattern and the capture-phase alternative considered.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request type
Bug fix (non-breaking change which fixes an issue)
Description
Fix bug where gallery on click action prevents default action for SPACE and ENTER