-
Notifications
You must be signed in to change notification settings - Fork 536
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
Introduce TrailingAction to ActionList #4634
Merged
Merged
Changes from all commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
7f21a16
Add fixes for ActionList
TylerJDev fa708b1
More type fixes
TylerJDev e087f87
temp type fixes
TylerJDev 76e2606
Add condition for inactive items
TylerJDev eab6fd9
add yet another condition
TylerJDev 8b4f311
Merge branch 'main' into tylerjdev/action-list-a11y-fixes
TylerJDev 614749a
chore(deps): bump changesets/action from 1.4.5 to 1.4.6 (#4282)
dependabot[bot] bfb8fe2
test(e2e): add e2e test for SelectPanel2 default story (#4279)
joshblack 4b18eed
Address a few v8 color bugs (#4278)
langermank d13668d
chore(deps-dev): bump ip from 2.0.0 to 2.0.1 (#4291)
dependabot[bot] 10d9866
Change how `ref` is handled
TylerJDev 0939a90
Merge branch 'main' into tylerjdev/action-list-a11y-fixes
TylerJDev cc6a63c
Merge branch 'main' into tylerjdev/action-list-a11y-fixes
TylerJDev 1cd9fb1
Merge branch 'main' into tylerjdev/action-list-a11y-fixes
TylerJDev 3d1daf3
Change types
TylerJDev 5999a77
Update storybook example types
TylerJDev 9f77b09
Update types on component
TylerJDev 087ab1f
Add another type
TylerJDev f4a5021
Update type in `SegmentedControl`
TylerJDev ba31e40
Add back `li`-only type
TylerJDev 8e2921d
Add onto `onSelect` type
TylerJDev afa8d9f
Merge branch 'main' into tylerjdev/action-list-a11y-fixes
TylerJDev 4b1f2b4
Update more types
TylerJDev 10cd551
Type fixes for `LinkItem`
TylerJDev 65c23c8
Changes from feedback
TylerJDev 70659ed
Change types
TylerJDev 1a9b3e0
Merge branch 'main' into tylerjdev/action-list-a11y-fixes
TylerJDev 1f783fa
Merge branch 'main' into tylerjdev/action-list-a11y-fixes
TylerJDev 6774f93
Replace `role="list"` with context
TylerJDev 5ed547f
Merge branch 'main' into tylerjdev/action-list-a11y-fixes
TylerJDev cf5ecf9
Add feature flag to `ActionList.Item
TylerJDev 2f13c76
Add back forwardedRef in cases where valid role is true
TylerJDev f32f416
Update FF name
TylerJDev 84f041e
Add lint disable
TylerJDev 55632b1
Update FF name
TylerJDev 8bc5c15
Merge branch 'main' into tylerjdev/action-list-a11y-fixes
TylerJDev ce70779
Add changeset
TylerJDev 3e8af88
Remove `list` condition
TylerJDev 4c8a4de
Rename FF
TylerJDev 0d076dc
Address feedback
TylerJDev d2faa9a
Add feature flag story
TylerJDev 54eab93
Add new test
TylerJDev d1c1d60
Merge branch 'main' into tylerjdev/action-list-a11y-fixes
TylerJDev c4fb363
Add export
khiga8 8b70194
Updated forwardRef to be polymorphic
khiga8 da5b5a8
Spike: Add trailingAction to ActionList.Item
khiga8 6d0bc54
Updated forwardRef to be polymorphic
khiga8 da464e9
TrailingAction style adjustments
TylerJDev 950ac4a
test(vrt): update snapshots
khiga8 1db6a02
Remove unused story
khiga8 b20fc5e
Limit TrailingAction props
khiga8 87bfa62
Fix missing href for as link
khiga8 9ad7d86
Add Inactive example
khiga8 c218363
Add styles for `showOnHover`
TylerJDev dd91f97
Fixed href overload issue
khiga8 dc216ad
Made sure that TrailingAction doesn't show when inactive state
khiga8 001fcf8
test(vrt): update snapshots
khiga8 a69a44c
Merge branch 'tylerjdev/action-list-a11y-fixes' into v-team-trailing-…
khiga8 35579ab
Add fixes for button styles
TylerJDev c67b0e1
Fix for flex styles
TylerJDev 66e5405
Update storybookd descriptions
khiga8 96a9ef3
Add block description example
khiga8 6011c9b
Add tests
TylerJDev 5028660
Remove FF from tests
TylerJDev 0bc749c
update e2e stories
TylerJDev 804153b
spike on allowing text (#4659)
khiga8 0152e99
Add visual tests
TylerJDev c238a6b
Update from display to visibility
khiga8 d0355a2
Create calm-crabs-raise.md
khiga8 8802b79
Disallow usage in `ActionMenu`
TylerJDev 3362ce5
Update ActionList.test.tsx
khiga8 676b276
Remove hover/focus styles
TylerJDev ea88abe
test(vrt): update snapshots
khiga8 088c981
Merge branch 'main' into v-team-trailing-action-action-list
khiga8 294f4d2
Apply suggestions from code review
khiga8 4667520
Apply suggestions from code review
khiga8 e9147b0
Fix merge conflict
khiga8 3058906
Remove Hover examples
khiga8 29fac6a
Remove showOnHover code
khiga8 a84033c
Add FF const back
TylerJDev 8a9b2d4
Remove some usage of `hoverStyles`
TylerJDev 5539174
test(vrt): update snapshots
TylerJDev ec25af5
Add props to TrailingAction
TylerJDev b1f65d6
update types
khiga8 9d53def
update docs
khiga8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@primer/react": minor | ||
--- | ||
|
||
Introduce ActionList.TrailingAction to support secondary action on ActionList.Item |
Binary file modified
BIN
+0 Bytes
(100%)
...ist.test.ts-snapshots/ActionList-Inactive-Multiselect-dark-colorblind-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+0 Bytes
(100%)
...ionList.test.ts-snapshots/ActionList-Inactive-Multiselect-dark-dimmed-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1 Byte
(100%)
....test.ts-snapshots/ActionList-Inactive-Multiselect-dark-high-contrast-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+0 Bytes
(100%)
...nts/ActionList.test.ts-snapshots/ActionList-Inactive-Multiselect-dark-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+0 Bytes
(100%)
...ist.test.ts-snapshots/ActionList-Inactive-Multiselect-dark-tritanopia-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3 Bytes
(100%)
...st.test.ts-snapshots/ActionList-Inactive-Multiselect-light-colorblind-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+11 Bytes
(100%)
...test.ts-snapshots/ActionList-Inactive-Multiselect-light-high-contrast-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-9 Bytes
(100%)
...ts/ActionList.test.ts-snapshots/ActionList-Inactive-Multiselect-light-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3 Bytes
(100%)
...st.test.ts-snapshots/ActionList-Inactive-Multiselect-light-tritanopia-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44.8 KB
...ist.test.ts-snapshots/ActionList-With-Trailing-Action-dark-colorblind-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44.2 KB
...ionList.test.ts-snapshots/ActionList-With-Trailing-Action-dark-dimmed-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44.5 KB
....test.ts-snapshots/ActionList-With-Trailing-Action-dark-high-contrast-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44.8 KB
...nts/ActionList.test.ts-snapshots/ActionList-With-Trailing-Action-dark-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44.8 KB
...ist.test.ts-snapshots/ActionList-With-Trailing-Action-dark-tritanopia-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+45.1 KB
...st.test.ts-snapshots/ActionList-With-Trailing-Action-light-colorblind-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+45.1 KB
...test.ts-snapshots/ActionList-With-Trailing-Action-light-high-contrast-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+45.1 KB
...ts/ActionList.test.ts-snapshots/ActionList-With-Trailing-Action-light-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+45.1 KB
...st.test.ts-snapshots/ActionList-With-Trailing-Action-light-tritanopia-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-61 Bytes
(100%)
...shots/components/Avatar.test.ts-snapshots/Avatar-Size-dark-colorblind-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,9 @@ import {Selection} from './Selection' | |
import {getVariantStyles, ItemContext, TEXT_ROW_HEIGHT, ListContext} from './shared' | ||
import type {VisualProps} from './Visuals' | ||
import {LeadingVisual, TrailingVisual} from './Visuals' | ||
import {TrailingAction} from './TrailingAction' | ||
import {ConditionalWrapper} from '../internal/components/ConditionalWrapper' | ||
import {invariant} from '../utils/invariant' | ||
import {useFeatureFlag} from '../FeatureFlags' | ||
|
||
const LiBox = styled.li<SxProp>(sx) | ||
|
@@ -71,14 +73,15 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>( | |
const [slots, childrenWithoutSlots] = useSlots(props.children, { | ||
leadingVisual: LeadingVisual, | ||
trailingVisual: TrailingVisual, | ||
trailingAction: TrailingAction, | ||
blockDescription: [Description, props => props.variant === 'block'], | ||
inlineDescription: [Description, props => props.variant !== 'block'], | ||
}) | ||
|
||
const {container, afterSelect, selectionAttribute, defaultTrailingVisual} = | ||
React.useContext(ActionListContainerContext) | ||
|
||
const buttonSemantics = useFeatureFlag('primer_react_action_list_item_as_button') | ||
const buttonSemanticsFeatureFlag = useFeatureFlag('primer_react_action_list_item_as_button') | ||
|
||
// Be sure to avoid rendering the container unless there is a default | ||
const wrappedDefaultTrailingVisual = defaultTrailingVisual ? ( | ||
|
@@ -125,12 +128,19 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>( | |
|
||
const itemRole = role || inferredItemRole | ||
|
||
if (slots.trailingAction) { | ||
invariant(!container, `ActionList.TrailingAction can not be used within a ${container}.`) | ||
} | ||
|
||
/** Infer the proper selection attribute based on the item's role */ | ||
let inferredSelectionAttribute: 'aria-selected' | 'aria-checked' | undefined | ||
if (itemRole === 'menuitemradio' || itemRole === 'menuitemcheckbox') inferredSelectionAttribute = 'aria-checked' | ||
else if (itemRole === 'option') inferredSelectionAttribute = 'aria-selected' | ||
|
||
const itemSelectionAttribute = selectionAttribute || inferredSelectionAttribute | ||
// Ensures ActionList.Item retains list item semantics if a valid ARIA role is applied, or if item is inactive | ||
const listSemantics = listRole === 'listbox' || listRole === 'menu' || inactive || container === 'NavList' | ||
const buttonSemantics = !listSemantics && !_PrivateItemWrapper && buttonSemanticsFeatureFlag | ||
|
||
const {theme} = useTheme() | ||
|
||
|
@@ -149,10 +159,32 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>( | |
}, | ||
} | ||
|
||
const hoverStyles = { | ||
'@media (hover: hover) and (pointer: fine)': { | ||
':hover:not([aria-disabled]):not([data-inactive])': { | ||
backgroundColor: `actionListItem.${variant}.hoverBg`, | ||
color: getVariantStyles(variant, disabled, inactive).hoverColor, | ||
boxShadow: `inset 0 0 0 max(1px, 0.0625rem) ${theme?.colors.actionListItem.default.activeBorder}`, | ||
}, | ||
'&:focus-visible, > a.focus-visible, &:focus.focus-visible': { | ||
outline: 'none', | ||
border: `2 solid`, | ||
boxShadow: `0 0 0 2px ${theme?.colors.accent.emphasis}`, | ||
}, | ||
':active:not([aria-disabled]):not([data-inactive])': { | ||
backgroundColor: `actionListItem.${variant}.activeBg`, | ||
color: getVariantStyles(variant, disabled, inactive).hoverColor, | ||
}, | ||
}, | ||
} | ||
|
||
const listItemStyles = { | ||
display: 'flex', | ||
// show between 2 items | ||
':not(:first-of-type)': {'--divider-color': theme?.colors.actionListItem.inlineDivider}, | ||
width: 'calc(100% - 16px)', | ||
marginX: buttonSemantics ? '2' : '0', | ||
...(buttonSemantics ? hoverStyles : {}), | ||
Comment on lines
+185
to
+187
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. @TylerJDev, do we still need this? 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. Kinda, this gives consistency between the link items and the regular items when you hover over the |
||
} | ||
|
||
const styles = { | ||
|
@@ -163,7 +195,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>( | |
paddingY: '6px', // custom value off the scale | ||
lineHeight: TEXT_ROW_HEIGHT, | ||
minHeight: 5, | ||
marginX: listVariant === 'inset' ? 2 : 0, | ||
marginX: listVariant === 'inset' && !buttonSemantics ? 2 : 0, | ||
borderRadius: 2, | ||
transition: 'background 33.333ms linear', | ||
color: getVariantStyles(variant, disabled, inactive).color, | ||
|
@@ -181,7 +213,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>( | |
appearance: 'none', | ||
background: 'unset', | ||
border: 'unset', | ||
width: listVariant === 'inset' ? 'calc(100% - 16px)' : '100%', | ||
width: listVariant === 'inset' && !buttonSemantics ? 'calc(100% - 16px)' : '100%', | ||
fontFamily: 'unset', | ||
textAlign: 'unset', | ||
marginY: 'unset', | ||
|
@@ -224,6 +256,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>( | |
borderTopWidth: showDividers ? `1px` : '0', | ||
borderColor: 'var(--divider-color, transparent)', | ||
}, | ||
|
||
// show between 2 items | ||
':not(:first-of-type)': {'--divider-color': theme?.colors.actionListItem.inlineDivider}, | ||
// hide divider after dividers & group header, with higher importance! | ||
|
@@ -268,8 +301,6 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>( | |
const inlineDescriptionId = `${itemId}--inline-description` | ||
const blockDescriptionId = `${itemId}--block-description` | ||
const inactiveWarningId = inactive && !showInactiveIndicator ? `${itemId}--warning-message` : undefined | ||
// Ensures ActionList.Item retains list item semantics if a valid ARIA role is applied, or if item is inactive | ||
const listSemantics = listRole === 'listbox' || listRole === 'menu' || inactive || container === 'NavList' | ||
|
||
const ButtonItemWrapper = React.forwardRef(({as: Component = 'button', children, ...props}, forwardedRef) => { | ||
return ( | ||
|
@@ -285,7 +316,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>( | |
}) as PolymorphicForwardRefComponent<React.ElementType, ActionListItemProps> | ||
|
||
let DefaultItemWrapper = React.Fragment | ||
if (buttonSemantics) { | ||
if (buttonSemanticsFeatureFlag) { | ||
khiga8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
DefaultItemWrapper = listSemantics ? React.Fragment : ButtonItemWrapper | ||
} | ||
|
||
|
@@ -313,7 +344,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>( | |
let containerProps | ||
let wrapperProps | ||
|
||
if (buttonSemantics) { | ||
if (buttonSemanticsFeatureFlag) { | ||
containerProps = _PrivateItemWrapper | ||
? {role: itemRole ? 'none' : undefined, ...props} | ||
: // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
|
@@ -337,9 +368,9 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>( | |
value={{variant, disabled, inactive: Boolean(inactiveText), inlineDescriptionId, blockDescriptionId}} | ||
> | ||
<LiBox | ||
ref={buttonSemantics || listSemantics ? forwardedRef : null} | ||
ref={buttonSemanticsFeatureFlag || listSemantics ? forwardedRef : null} | ||
sx={ | ||
buttonSemantics | ||
buttonSemanticsFeatureFlag | ||
? merge<BetterSystemStyleObject>( | ||
listSemantics || _PrivateItemWrapper ? styles : listItemStyles, | ||
listSemantics || _PrivateItemWrapper ? sxProp : {}, | ||
|
@@ -424,6 +455,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>( | |
{slots.blockDescription} | ||
</Box> | ||
</ItemWrapper> | ||
{!inactive && Boolean(slots.trailingAction) && !container && slots.trailingAction} | ||
</LiBox> | ||
</ItemContext.Provider> | ||
) | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
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 realized block variant is supported for Description so added this
ActionList.Description variant="block"
example!@langermank Is the Trailing Action alignment okay as is, or should it be vertically centered?
From storybook draft:
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.
For reference, this is with a "Trailing Visual":
It's similar with the "inactive" button. If we should modify this instance, do we need to adjust the others?