From 972e045145711e39fd6fa167cb87fa05e062272c Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 28 Jun 2021 11:14:47 +1000 Subject: [PATCH] assorted filter pill fixes (#5987) --- .changeset/healthy-spoons-dance.md | 5 + .changeset/loud-poems-crash.md | 5 + .changeset/stale-hornets-remember.md | 5 + .changeset/tough-walls-kneel.md | 5 + design-system/packages/pill/src/index.tsx | 204 +++++++++--------- .../packages/popover/src/Popover.tsx | 3 +- .../fields/src/types/text/views/index.tsx | 2 +- .../admin-ui/pages/ListPage/FilterList.tsx | 36 ++-- 8 files changed, 149 insertions(+), 116 deletions(-) create mode 100644 .changeset/healthy-spoons-dance.md create mode 100644 .changeset/loud-poems-crash.md create mode 100644 .changeset/stale-hornets-remember.md create mode 100644 .changeset/tough-walls-kneel.md diff --git a/.changeset/healthy-spoons-dance.md b/.changeset/healthy-spoons-dance.md new file mode 100644 index 00000000000..a20da6e97c0 --- /dev/null +++ b/.changeset/healthy-spoons-dance.md @@ -0,0 +1,5 @@ +--- +'@keystone-next/keystone': patch +--- + +Added assorted quality of life and screen reader improvements to Filter pills and dialogs in the admin-ui diff --git a/.changeset/loud-poems-crash.md b/.changeset/loud-poems-crash.md new file mode 100644 index 00000000000..698b58ec707 --- /dev/null +++ b/.changeset/loud-poems-crash.md @@ -0,0 +1,5 @@ +--- +'@keystone-ui/popover': patch +--- + +Added aria-hidden to dialog container so screen readers can't access when the dialog is not visible. diff --git a/.changeset/stale-hornets-remember.md b/.changeset/stale-hornets-remember.md new file mode 100644 index 00000000000..475cc730b4e --- /dev/null +++ b/.changeset/stale-hornets-remember.md @@ -0,0 +1,5 @@ +--- +'@keystone-ui/pill': major +--- + +Added containerProps prop, these are spread onto the containing element. All other props are now spread onto the internal PillButton component (this change is inclusive of refs). diff --git a/.changeset/tough-walls-kneel.md b/.changeset/tough-walls-kneel.md new file mode 100644 index 00000000000..523d28ff557 --- /dev/null +++ b/.changeset/tough-walls-kneel.md @@ -0,0 +1,5 @@ +--- +'@keystone-next/fields': patch +--- + +Fixed autoFocus always being active in the text field Filter component. diff --git a/design-system/packages/pill/src/index.tsx b/design-system/packages/pill/src/index.tsx index 216d877843c..fc8b3a5559a 100644 --- a/design-system/packages/pill/src/index.tsx +++ b/design-system/packages/pill/src/index.tsx @@ -7,130 +7,132 @@ import { XIcon } from '@keystone-ui/icons/icons/XIcon'; type Tone = 'active' | 'passive' | 'positive' | 'warning' | 'negative' | 'help'; type Weight = 'bold' | 'light'; -const PillButton = ({ - tone: toneKey, - weight, - onClick, - tabIndex, - ...props -}: { +type PillButtonProps = { tone: Tone; weight: Weight; -} & ButtonHTMLAttributes) => { - const { radii, spacing, tones, typography } = useTheme(); +} & ButtonHTMLAttributes; - const isInteractive = !!onClick; +const PillButton = forwardRef( + ({ tone: toneKey, weight, onClick, tabIndex, ...props }, ref) => { + const { radii, spacing, tones, typography } = useTheme(); - const tone = tones[toneKey]; - const tokens = { - bold: { - background: tone.fill[0], - foreground: tone.fillForeground[0], - focus: { - shadow: `0 0 0 2px ${tone.focusRing}`, - }, - hover: { - background: tone.fill[1], + const isInteractive = !!onClick; + + const tone = tones[toneKey]; + const tokens = { + bold: { + background: tone.fill[0], + foreground: tone.fillForeground[0], + focus: { + shadow: `0 0 0 2px ${tone.focusRing}`, + }, + hover: { + background: tone.fill[1], + }, + active: { + background: tone.fill[2], + }, }, - active: { - background: tone.fill[2], + light: { + background: tone.tint[0], + foreground: tone.foreground[0], + focus: { + shadow: `0 0 0 2px ${tone.focusRing}`, + }, + hover: { + foreground: tone.foreground[1], + background: tone.tint[1], + }, + active: { + foreground: tone.foreground[2], + background: tone.tint[2], + }, }, - }, - light: { - background: tone.tint[0], - foreground: tone.foreground[0], - focus: { - shadow: `0 0 0 2px ${tone.focusRing}`, + }[weight]; + + const baseStyles = { + alignItems: 'center', + appearance: 'none', + background: 'none', + backgroundColor: tokens.background, + border: 0, + color: tokens.foreground, + display: 'flex', + fontSize: typography.fontSize.small, + fontWeight: typography.fontWeight.medium, + justifyContent: 'center', + maxWidth: '100%', + minWidth: 1, + outline: 0, + padding: `${spacing.small}px ${spacing.medium}px`, + + ':first-of-type': { + paddingRight: spacing.small, + borderTopLeftRadius: radii.full, + borderBottomLeftRadius: radii.full, + marginRight: 1, }, - hover: { - foreground: tone.foreground[1], - background: tone.tint[1], + ':last-of-type': { + paddingLeft: spacing.small, + borderTopRightRadius: radii.full, + borderBottomRightRadius: radii.full, }, - active: { - foreground: tone.foreground[2], - background: tone.tint[2], + ':only-of-type': { + paddingLeft: spacing.medium, + paddingRight: spacing.medium, }, - }, - }[weight]; + } as const; - const baseStyles = { - alignItems: 'center', - appearance: 'none', - background: 'none', - backgroundColor: tokens.background, - border: 0, - color: tokens.foreground, - display: 'flex', - fontSize: typography.fontSize.small, - fontWeight: typography.fontWeight.medium, - justifyContent: 'center', - maxWidth: '100%', - minWidth: 1, - outline: 0, - padding: `${spacing.small}px ${spacing.medium}px`, + const interactiveStyles = isInteractive + ? { + cursor: 'pointer', + ':focus': { + boxShadow: tokens.focus.shadow, + }, + ':hover,:focus': { + backgroundColor: tokens.hover.background, + color: tokens.hover.foreground, + }, + ':active': { + backgroundColor: tokens.active.background, + color: tokens.active.foreground, + }, + } + : {}; - ':first-of-type': { - paddingRight: spacing.small, - borderTopLeftRadius: radii.full, - borderBottomLeftRadius: radii.full, - marginRight: 1, - }, - ':last-of-type': { - paddingLeft: spacing.small, - borderTopRightRadius: radii.full, - borderBottomRightRadius: radii.full, - }, - ':only-of-type': { - paddingLeft: spacing.medium, - paddingRight: spacing.medium, - }, - } as const; - - const interactiveStyles = isInteractive - ? { - cursor: 'pointer', - ':focus': { - boxShadow: tokens.focus.shadow, - }, - ':hover,:focus': { - backgroundColor: tokens.hover.background, - color: tokens.hover.foreground, - }, - ':active': { - backgroundColor: tokens.active.background, - color: tokens.active.foreground, - }, - } - : {}; - - return ( -