diff --git a/.changeset/loose-lizards-drop.md b/.changeset/loose-lizards-drop.md new file mode 100644 index 0000000000..27c5ad32e9 --- /dev/null +++ b/.changeset/loose-lizards-drop.md @@ -0,0 +1,8 @@ +--- +"@ebay/skin": patch +"@ebay/ebayui-core": patch +"@ebay/ebayui-core-react": patch +"@evo-web/marko": patch +--- + +replace aria-pressed with CSS class for menu button selected state diff --git a/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/__snapshots__/render.spec.tsx.snap b/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/__snapshots__/render.spec.tsx.snap index 51f0b0f73c..30e1b6771a 100644 --- a/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/__snapshots__/render.spec.tsx.snap +++ b/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/__snapshots__/render.spec.tsx.snap @@ -76,7 +76,6 @@ exports[` rendering > renders collection story correctly 1`] = @@ -197,7 +196,6 @@ exports[` rendering > renders menu expanded story correctly 1` @@ -220,11 +218,42 @@ exports[` rendering > renders menu expanded story correctly 1` `; +exports[` rendering > renders menu selected story correctly 1`] = ` + + + + Menu Selected + + - + Filter Applied + + + + + + + +`; + exports[` rendering > renders menu story correctly 1`] = ` diff --git a/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/index.spec.tsx b/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/index.spec.tsx index 160236144d..6c316df911 100644 --- a/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/index.spec.tsx +++ b/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/index.spec.tsx @@ -109,6 +109,32 @@ describe("", () => { expect(container.querySelector(".filter-chip__trailing")).toBeInTheDocument(); }); + + it("should not render aria-pressed", () => { + const { getByRole } = render(Menu Filter); + + expect(getByRole("button")).not.toHaveAttribute("aria-pressed"); + }); + + it("should add filter-chip--selected class when selected", () => { + const { container } = render( + + Menu Filter + , + ); + + expect(container.querySelector(".filter-chip")).toHaveClass("filter-chip--selected"); + }); + + it("should show clipped text when selected", () => { + const { container } = render( + + Menu Filter + , + ); + + expect(container.querySelector(".clipped")).toHaveTextContent("- Filter Applied"); + }); }); describe("anchor variant", () => { diff --git a/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/index.stories.tsx b/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/index.stories.tsx index 36c3da2b3e..f875b0ae2b 100644 --- a/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/index.stories.tsx +++ b/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/index.stories.tsx @@ -171,6 +171,12 @@ export const Menu: StoryFn = (args) => ( ); +export const MenuSelected: StoryFn = (args) => ( + + Menu Selected + +); + export const MenuExpanded: StoryFn = (args) => ( Menu Expanded diff --git a/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/render.spec.tsx b/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/render.spec.tsx index e9f388188f..0c64e56a03 100644 --- a/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/render.spec.tsx +++ b/packages/ebayui-core-react/src/ebay-filter-chip/__tests__/render.spec.tsx @@ -11,6 +11,7 @@ const { Expressive, ExpressiveSelected, Menu, + MenuSelected, MenuExpanded, Anchor, AnchorSelected, @@ -49,6 +50,11 @@ describe(" rendering", () => { expect(container).toMatchSnapshot(); }); + it("renders menu selected story correctly", () => { + const { container } = render(); + expect(container).toMatchSnapshot(); + }); + it("renders menu expanded story correctly", () => { const { container } = render(); expect(container).toMatchSnapshot(); diff --git a/packages/ebayui-core-react/src/ebay-filter-chip/filter-chip.tsx b/packages/ebayui-core-react/src/ebay-filter-chip/filter-chip.tsx index 747bfdc666..3f66cf1115 100644 --- a/packages/ebayui-core-react/src/ebay-filter-chip/filter-chip.tsx +++ b/packages/ebayui-core-react/src/ebay-filter-chip/filter-chip.tsx @@ -55,7 +55,8 @@ const EbayFilterChip: FC = ({ const selected = selectedControlled !== undefined ? selectedControlled : uncontrolledSelected; const expanded = expandedControlled !== undefined ? expandedControlled : uncontrolledExpanded; - const isAnchor = !!href && variant !== "menu"; + const isMenu = variant === "menu"; + const isAnchor = !!href && !isMenu; useLayoutEffect(() => { containerRef.current?.classList?.add("filter-chip--animated"); @@ -66,7 +67,7 @@ const EbayFilterChip: FC = ({ let newExpanded = expanded; let newSelected = selected; - if (variant === "menu") { + if (isMenu) { newExpanded = !expanded; setUncontrolledExpanded(newExpanded); } else { @@ -85,7 +86,7 @@ const EbayFilterChip: FC = ({ "filter-chip", { "filter-chip--expressive": variant === "expressive", - "filter-chip--selected": isAnchor && selected, + "filter-chip--selected": (isAnchor || isMenu) && selected, }, className, ); @@ -100,8 +101,8 @@ const EbayFilterChip: FC = ({ onClick={handleClick} href={!disabled ? href : undefined} type={!isAnchor ? "button" : undefined} - aria-pressed={!isAnchor ? (selected ? "true" : "false") : undefined} - aria-expanded={variant === "menu" ? (expanded ? "true" : "false") : undefined} + aria-pressed={!isAnchor && !isMenu ? (selected ? "true" : "false") : undefined} + aria-expanded={isMenu ? (expanded ? "true" : "false") : undefined} disabled={!isAnchor ? disabled : undefined} > {variant === "expressive" ? {image} : null} @@ -110,7 +111,7 @@ const EbayFilterChip: FC = ({ {children} - {selected && isAnchor ? - {a11ySelectedText} : null} + {selected && (isAnchor || isMenu) ? - {a11ySelectedText} : null} {variant === "menu" ? : null} diff --git a/packages/ebayui-core/src/components/ebay-filter-chip/filter-chip.stories.ts b/packages/ebayui-core/src/components/ebay-filter-chip/filter-chip.stories.ts index 949eb15999..2490450780 100644 --- a/packages/ebayui-core/src/components/ebay-filter-chip/filter-chip.stories.ts +++ b/packages/ebayui-core/src/components/ebay-filter-chip/filter-chip.stories.ts @@ -56,7 +56,7 @@ export default { a11ySelectedText: { control: { type: "string" }, description: - 'Localized, for anchor variant: the clipped text to show when the filter is set. Defaults to "- filter applied"', + 'Localized, for anchor variant: the clipped text to show when the filter is set. Defaults to "- Filter Applied"', }, onClick: { action: "on-click", diff --git a/packages/ebayui-core/src/components/ebay-filter-chip/index.marko b/packages/ebayui-core/src/components/ebay-filter-chip/index.marko index 3c8d3c6ff4..2323167dc4 100644 --- a/packages/ebayui-core/src/components/ebay-filter-chip/index.marko +++ b/packages/ebayui-core/src/components/ebay-filter-chip/index.marko @@ -21,13 +21,13 @@ $ const rootTag = isAnchor ? "a" : "button"; "filter-chip", state.mounted && "filter-chip--animated", variant === "expressive" && "filter-chip--expressive", - isAnchor && state.selected && "filter-chip--selected", + (isAnchor || variant === "menu") && state.selected && "filter-chip--selected", inputClass ] type=!isAnchor && "button" href=!disabled ? href : undefined disabled=!isAnchor ? disabled : undefined - aria-pressed=!isAnchor && (state.selected ? "true" : "false") + aria-pressed=!isAnchor && variant !== "menu" && (state.selected ? "true" : "false") aria-expanded=variant === "menu" && (state.expanded ? "true" : "false") on-click("handleButtonClick") > @@ -43,7 +43,7 @@ $ const rootTag = isAnchor ? "a" : "button"; <${renderBody}/> - + - ${a11ySelectedText} diff --git a/packages/ebayui-core/src/components/ebay-filter-chip/test/__snapshots__/test.server.js.snap b/packages/ebayui-core/src/components/ebay-filter-chip/test/__snapshots__/test.server.js.snap index de0cae4089..b5b1eaa87f 100644 --- a/packages/ebayui-core/src/components/ebay-filter-chip/test/__snapshots__/test.server.js.snap +++ b/packages/ebayui-core/src/components/ebay-filter-chip/test/__snapshots__/test.server.js.snap @@ -116,7 +116,6 @@ exports[`ebay-filter-chip > renders menu button 1`] = ` "[36m[39m [36m[39m @@ -154,7 +153,6 @@ exports[`ebay-filter-chip > renders menu button expanded 1`] = ` "[36m[39m [36m[39m @@ -192,14 +190,18 @@ exports[`ebay-filter-chip > renders menu button expanded and selected 1`] = ` "[36m[39m [36m[39m [36m[39m [0mFilter[0m + [36m[39m + [0m- Filter Applied[0m + [36m[39m [36m[39m [36m renders menu button selected 1`] = ` "[36m[39m [36m[39m [36m[39m [0mFilter[0m + [36m[39m + [0m- Filter Applied[0m + [36m[39m [36m[39m [36m renders with filter 1`] = ` [36m[39m @@ -1307,7 +1306,6 @@ exports[`menu-button > renders with footer 1`] = ` [36m[39m @@ -2331,7 +2329,6 @@ exports[`menu-button > renders with type=checkbox and checked=false and as filte [36m[39m @@ -2568,7 +2565,6 @@ exports[`menu-button > renders with type=checkbox and checked=true and as filter [36m[39m @@ -2805,7 +2801,6 @@ exports[`menu-button > renders with type=radio and checked=false and as filter 1 [36m[39m @@ -3046,7 +3041,6 @@ exports[`menu-button > renders with type=radio and checked=true and as filter 1` [36m[39m diff --git a/packages/evo-marko/src/tags/evo-filter-chip/examples/anchor.marko b/packages/evo-marko/src/tags/evo-filter-chip/examples/anchor.marko index a298e739d0..f748b57c04 100644 --- a/packages/evo-marko/src/tags/evo-filter-chip/examples/anchor.marko +++ b/packages/evo-marko/src/tags/evo-filter-chip/examples/anchor.marko @@ -1,4 +1,4 @@ - + <@icon> @icon> diff --git a/packages/evo-marko/src/tags/evo-filter-chip/index.marko b/packages/evo-marko/src/tags/evo-filter-chip/index.marko index 32445b11af..db02dfb2ff 100644 --- a/packages/evo-marko/src/tags/evo-filter-chip/index.marko +++ b/packages/evo-marko/src/tags/evo-filter-chip/index.marko @@ -44,7 +44,7 @@ export interface Input ...input as Marko.HTML.Button disabled=disabled type="button" - aria-selected=(selected ? "true" : "false")/> + aria-selected=!isMenu && (selected ? "true" : "false")/> @@ -54,6 +54,7 @@ export interface Input "filter-chip", mounted && "filter-chip--animated", variant === "expressive" && "filter-chip--expressive", + (isAnchor || isMenu) && selected && "filter-chip--selected", inputClass, ] href=(!disabled ? href : undefined) @@ -80,7 +81,7 @@ export interface Input <${content}/> - + ${" "}- ${a11ySelectedText} diff --git a/packages/skin/dist/filter-chip/filter-chip.css b/packages/skin/dist/filter-chip/filter-chip.css index 18a8c74a6f..ccd4c9294e 100644 --- a/packages/skin/dist/filter-chip/filter-chip.css +++ b/packages/skin/dist/filter-chip/filter-chip.css @@ -144,6 +144,7 @@ button.filter-chip--expressive { } a.filter-chip--selected, +button.filter-chip.filter-chip--selected, button.filter-chip[aria-pressed="true"] { animation: fill-horizontal-background 0s var(--motion-easing-quick-enter) forwards; @@ -158,6 +159,7 @@ button.filter-chip[aria-pressed="true"] { } a.filter-chip--selected:after, +button.filter-chip.filter-chip--selected:after, button.filter-chip[aria-pressed="true"]:after { background-color: var(--color-state-layer-neutral-on-strong); content: ""; @@ -168,6 +170,11 @@ button.filter-chip[aria-pressed="true"]:after { a.filter-chip--selected:not([disabled], [aria-disabled="true"]):hover:after, a.filter-chip--selected[href]:hover:after, +button.filter-chip.filter-chip--selected:not( + [disabled], + [aria-disabled="true"] + ):hover:after, +button.filter-chip.filter-chip--selected[href]:hover:after, button.filter-chip[aria-pressed="true"]:not( [disabled], [aria-disabled="true"] @@ -181,6 +188,11 @@ a.filter-chip--selected:not( [aria-disabled="true"] ):focus-visible:after, a.filter-chip--selected[href]:focus-visible:after, +button.filter-chip.filter-chip--selected:not( + [disabled], + [aria-disabled="true"] + ):focus-visible:after, +button.filter-chip.filter-chip--selected[href]:focus-visible:after, button.filter-chip[aria-pressed="true"]:not( [disabled], [aria-disabled="true"] @@ -191,6 +203,11 @@ button.filter-chip[aria-pressed="true"][href]:focus-visible:after { a.filter-chip--selected:not([disabled], [aria-disabled="true"]):active:after, a.filter-chip--selected[href]:active:after, +button.filter-chip.filter-chip--selected:not( + [disabled], + [aria-disabled="true"] + ):active:after, +button.filter-chip.filter-chip--selected[href]:active:after, button.filter-chip[aria-pressed="true"]:not( [disabled], [aria-disabled="true"] @@ -199,6 +216,7 @@ button.filter-chip[aria-pressed="true"][href]:active:after { background-color: var(--color-state-layer-pressed-on-strong); } +button.filter-chip--animated.filter-chip--selected, button.filter-chip--animated[aria-pressed="true"] { animation-duration: var(--motion-duration-medium-2); transition: color var(--motion-duration-instant) diff --git a/packages/skin/src/sass/filter-chip/filter-chip.scss b/packages/skin/src/sass/filter-chip/filter-chip.scss index 8e991f4f62..b8362671a4 100644 --- a/packages/skin/src/sass/filter-chip/filter-chip.scss +++ b/packages/skin/src/sass/filter-chip/filter-chip.scss @@ -35,12 +35,14 @@ a.filter-chip--expressive { } button.filter-chip[aria-pressed="true"], +button.filter-chip.filter-chip--selected, a.filter-chip--selected { @include chip-mixins.selected; @include state-layer.strong; } -button.filter-chip--animated[aria-pressed="true"] { +button.filter-chip--animated[aria-pressed="true"], +button.filter-chip--animated.filter-chip--selected { @include chip-mixins.selected-animation; } diff --git a/packages/skin/src/sass/filter-chip/stories/menu-button-chip.stories.js b/packages/skin/src/sass/filter-chip/stories/menu-button-chip.stories.js index 212bfadde4..a155a759e9 100644 --- a/packages/skin/src/sass/filter-chip/stories/menu-button-chip.stories.js +++ b/packages/skin/src/sass/filter-chip/stories/menu-button-chip.stories.js @@ -1,7 +1,7 @@ export default { title: "Skin/Filter Chip/Menu" }; export const collapsed = () => ` - + Football @@ -10,7 +10,7 @@ export const collapsed = () => ` `; export const expanded = () => ` - + Football @@ -19,26 +19,28 @@ export const expanded = () => ` `; export const collapsedSelected = () => ` - + Football + Filter Applied `; export const expandedSelected = () => ` - + Football + Filter Applied `; export const RTL = () => ` - + Football @@ -47,8 +49,39 @@ export const RTL = () => ` `; +export const expressiveCollapsed = () => ` + + + + + Football + + + + +`; + +export const expressiveCollapsedSelected = () => ` + + + + + Football + + + + Filter Applied + +`; + export const textSpacing = () => ` - + Football diff --git a/src/routes/_index/components/filter-chip/css+page.marko b/src/routes/_index/components/filter-chip/css+page.marko index e32d5eb511..1b20e2e8f1 100644 --- a/src/routes/_index/components/filter-chip/css+page.marko +++ b/src/routes/_index/components/filter-chip/css+page.marko @@ -85,7 +85,7 @@ Football - - filter applied + - Filter Applied @@ -109,7 +109,7 @@ Football - - filter applied + - Filter Applied @@ -213,7 +213,7 @@ Pet Supplies - - filter applied + - Filter Applied @@ -246,7 +246,7 @@ Football - - filter applied + - Filter Applied @@ -261,7 +261,7 @@ - + Sport: - @@ -273,7 +273,7 @@ - + Sport: - @@ -290,7 +290,7 @@ - + Sport: Football @@ -300,12 +300,15 @@ + + Filter Applied + - + Sport: Football @@ -315,6 +318,9 @@ + + Filter Applied +