-
Notifications
You must be signed in to change notification settings - Fork 538
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
Adds inactive state to ActionList items #3913
Conversation
makes unavailable message consistent fixes LinkItem styling
🦋 Changeset detectedLatest commit: 9ef7b72 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Uh oh! @mperrotti, the image you shared is missing helpful alt text. Check your pull request body. Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image. Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs. |
size-limit report 📦
|
) | ||
|
||
const keyPressHandler = React.useCallback( | ||
(event: React.KeyboardEvent<HTMLLIElement>) => { | ||
if (disabled) return | ||
if (disabled || inactive) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not calling any handlers passed to onSelect
for inactive items. This would also make it impossible to render a dialog when the user clicks the item. I think this is a reasonable limitation to begin with, and we can always update the implementation to support click/selection handlers so users can show a Dialog
if we find we need to.
Do you agree that it's safe to prohibit onSelect
on inactive items for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a draft PR to update the interface guidelines: primer/design#654
I'll close it if we think we do need to support click/selection behavior on inactive items.
I'll merge it if we don't think we need to support click/selection behavior on inactive items.
src/ActionList/Item.tsx
Outdated
import Box, {BoxProps} from '../Box' | ||
import {Tooltip} from '../drafts' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using the new, accessible Tooltip. Is this safe to use even though it's still in the experimental phase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In terms of using the new draft Tooltip, I think it is safe. It is unlikely to have API changes but still possible since it is in the experimental stage. The only API surface that is exposed in Actionlist API I see is the type of the text. Currently text is string
and undefined
type and I would say it is unlikely that it will change.
On the other hand, tooltip is still going through the accessibility sign-off review but compared to the stable one it solves multiple problems and it is more accessible. I think trying out the new tooltip in Primer rather than dotcom first seems like a good idea to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Posted a comment/question about the usage as well #3913 (comment) - very keen to hear what you think!
src/ActionList/Item.tsx
Outdated
import Box, {BoxProps} from '../Box' | ||
import {Tooltip} from '../drafts' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I try and run tests locally and import the "new" Tooltip, I got this mysterious error:
FAIL src/ActionList/ActionList.test.tsx
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'LeadingVisual')
226 | export type NavListLeadingVisualProps = ActionListLeadingVisualProps
227 |
> 228 | const LeadingVisual = ActionList.LeadingVisual
| ^
229 |
230 | LeadingVisual.displayName = 'NavList.LeadingVisual'
231 |
at Object.LeadingVisual (src/NavList/NavList.tsx:228:34)
at Object.require (src/NavList/index.ts:1:1)
at Object.require (src/drafts/index.ts:51:1)
at Object.require (src/ActionList/Item.tsx:18:1)
at Object.require (src/ActionList/index.ts:3:1)
at Object.require (src/index.ts:49:1)
at Object.require (src/utils/testing.tsx:7:1)
at Object.require (src/utils/test-matchers.tsx:7:1)
Any idea what might be causing this? I couldn't figure it out.
src/ActionList/Item.tsx
Outdated
{ | ||
// If it's inactive and isn't rendered in a container like ActionMenu or SelectPanel, render a leading visual with a tooltip | ||
inactive && container === undefined ? ( | ||
<Tooltip text={inactiveText}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cursor is on the entire disabled item, should the tooltip also be on the whole item or just the icon?
inactive-item.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the icon
What is the overlap with
As far as I remember, |
Just to confirm, I see in ActionList, we always add an alert icon. But in ActionMenu, we only add an alert icon if there is already a leading visual. Is that intentional? Side note: When the other items don't have icons, the alert icon moves the position of the label. Should we try to keep the labels aligned? For example, by using trailingVisual for alert instead of leading? |
Disabled items don't need to meet the minimum contrast and don't need a message explaining why it's disabled. cc @alexislucio |
ActionMenu actually doesn't need to show the alert icon at all since we show the message inline. I just kept it as another visual signal that the item doesn't work. I could easily change it so that ActionMenu items never render the alert icon. What do you think? |
This is such a rare state that I didn't think we need to worry about the alignment as much as we do for things like single select. However, I like your idea about using the trailing visual slot. Let me play with it and see how it feels. |
Is there a use case for disabled items with low contrast that's not covered by inactive? 🤔
Fair enough! |
If it's disabled and doesn't need to be conveyed to screen reader users. @alexislucio or somebody from a11y could probably give a more detailed answer. We have some info in the interface guidelines: https://primer.style/components/action-list#tooltips-and-dialogs-on-inactive-items |
I took the suggestion to render the inactive indicator in the trailing visual slot to preserve the alignment. Good call @siddharthkp ! |
src/ActionList/shared.ts
Outdated
@@ -52,18 +58,21 @@ type MenuItemProps = { | |||
'aria-labelledby'?: string | |||
'aria-describedby'?: string | |||
role?: string | |||
'data-inactive'?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be a prop. We set this based on inactiveText
value right?
</ActionMenu> | ||
) | ||
|
||
// TODO: Uncomment this story when we have inactive buttons |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since inactive buttons have been merged this can be uncommented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the prompt replies @mperrotti!
Left a couple of comments mainly
data-inactive
does not need to be a prop
Would be great to see the following in a follow-up PR
- Uncomment the story with the inactiveButton
- Add more comprehensive documentation for
inactiveText
ie- Its shown as tooltip on icon in
ActionList
and as description inActionMenu
- It replaces LeadingVisual if one is already present and adds/replaces TrailingVisual if not. I feel this will be a bit of a surprise to consumers otherwise.
- In case of a link item, it behaves in a completely different manner.
- Its shown as tooltip on icon in
Also look forward to the Tooltip
related future bugfix that is independent of this PR.
Other than that this looks good to me. I will also close out the associated discussion with a few comments for posterity. Thanks for all your efforts!
I'm not sure what you mean about the behavior being completely different on link items. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tooltip usage is looking good! ✨
Relates to https://github.com/github/primer/issues/2677
Screenshots
InactiveExample-InactiveItem.mp4
Changelog
Supports inactive ActionList items by letting users pass the required message to the
inactiveText
propNew
inactiveText
prop on ActionList.ItemChanged
Removed
Rollout strategy
Testing & Reviewing
ActionList
,ActionMenu
, andNavList
that demonstrate inactive list itemsMerge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.