Skip to content

Commit 6e7da1e

Browse files
TylerJDevsiddharthkp
andauthoredFeb 7, 2025··
ActionList: Allow items to remain focusable when disabled (#4481)
* Allow `ActionMenu` items, or `SelectPanel` items to be focusable when `disabled` * Add changeset * Update PR based on feedback * Fix for test --------- Co-authored-by: Siddharth Kshetrapal <siddharthkp@github.com>
1 parent 6381219 commit 6e7da1e

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed
 

‎.changeset/tall-ravens-hope.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': patch
3+
---
4+
5+
Allows `ActionMenu` and `SelectPanel` items to remain focusable when `disabled`

‎packages/react/src/ActionList/Item.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,20 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
317317
const selectableRoles = ['menuitemradio', 'menuitemcheckbox', 'option']
318318
const includeSelectionAttribute = itemSelectionAttribute && itemRole && selectableRoles.includes(itemRole)
319319

320+
let focusable
321+
322+
// if item is disabled and is of type (menuitem*, option) it should remain focusable, if inactive, apply the same rules
323+
if ((disabled && !inferredItemRole) || showInactiveIndicator) {
324+
focusable = true
325+
}
326+
320327
const menuItemProps = {
321328
onClick: clickHandler,
322329
onKeyPress: !buttonSemantics ? keyPressHandler : undefined,
323330
'aria-disabled': disabled ? true : undefined,
324331
'data-inactive': inactive ? true : undefined,
325332
'data-loading': loading && !inactive ? true : undefined,
326-
tabIndex: disabled || showInactiveIndicator ? undefined : 0,
333+
tabIndex: focusable ? undefined : 0,
327334
'aria-labelledby': `${labelId} ${slots.trailingVisual ? trailingVisualId : ''} ${
328335
slots.inlineDescription ? inlineDescriptionId : ''
329336
}`,

‎packages/react/src/ActionMenu/ActionMenu.features.stories.tsx

+56
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,59 @@ export const Submenus = () => (
282282
</ActionMenu.Overlay>
283283
</ActionMenu>
284284
)
285+
286+
export const DisabledItems = () => (
287+
<ActionMenu>
288+
<ActionMenu.Button>Open menu</ActionMenu.Button>
289+
<ActionMenu.Overlay width="auto">
290+
<ActionList>
291+
<ActionList.Item disabled={true}>
292+
Workflows
293+
<ActionList.LeadingVisual>
294+
<WorkflowIcon />
295+
</ActionList.LeadingVisual>
296+
</ActionList.Item>
297+
<ActionList.Item onSelect={() => alert('Archived items clicked')}>
298+
Archived items
299+
<ActionList.LeadingVisual>
300+
<ArchiveIcon />
301+
</ActionList.LeadingVisual>
302+
</ActionList.Item>
303+
<ActionList.LinkItem href="/">
304+
Settings
305+
<ActionList.LeadingVisual>
306+
<GearIcon />
307+
</ActionList.LeadingVisual>
308+
</ActionList.LinkItem>
309+
<ActionList.Item disabled={true}>
310+
Make a copy
311+
<ActionList.LeadingVisual>
312+
<CopyIcon />
313+
</ActionList.LeadingVisual>
314+
</ActionList.Item>
315+
<ActionList.Divider />
316+
<ActionList.Group>
317+
<ActionList.GroupHeading>Github projects</ActionList.GroupHeading>
318+
<ActionList.LinkItem href="/">
319+
What&apos;s new
320+
<ActionList.LeadingVisual>
321+
<RocketIcon />
322+
</ActionList.LeadingVisual>
323+
</ActionList.LinkItem>
324+
<ActionList.LinkItem href="/">
325+
Give feedback
326+
<ActionList.LeadingVisual>
327+
<CommentIcon />
328+
</ActionList.LeadingVisual>
329+
</ActionList.LinkItem>
330+
<ActionList.LinkItem href="/">
331+
GitHub Docs
332+
<ActionList.LeadingVisual>
333+
<BookIcon />
334+
</ActionList.LeadingVisual>
335+
</ActionList.LinkItem>
336+
</ActionList.Group>
337+
</ActionList>
338+
</ActionMenu.Overlay>
339+
</ActionMenu>
340+
)

0 commit comments

Comments
 (0)
Please sign in to comment.