diff --git a/.changeset/blue-dragons-marry.md b/.changeset/blue-dragons-marry.md new file mode 100644 index 00000000000..040a6d1b931 --- /dev/null +++ b/.changeset/blue-dragons-marry.md @@ -0,0 +1,11 @@ +--- +"@primer/react": patch +--- + +Adds truncation features to the LabelGroup component: +- truncate LabelGroup children after a static number of children (for example, truncate after the 5th label) +- truncate LabelGroup children to fit in the width of the parent +- show full list in an Overlay +- show full list inline + + diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-colorblind-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-colorblind-linux.png index 8c33f704f80..1e23872f399 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-colorblind-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-colorblind-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-dimmed-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-dimmed-linux.png index e28973b7417..e36019d62f5 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-dimmed-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-dimmed-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-high-contrast-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-high-contrast-linux.png index 9b9039f5076..a8a6683fcff 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-high-contrast-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-high-contrast-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-linux.png index 917e8babe7a..a9486d636b4 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-tritanopia-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-tritanopia-linux.png index 917e8babe7a..1e23872f399 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-tritanopia-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-dark-tritanopia-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-colorblind-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-colorblind-linux.png index 98f27f8aa1b..02dcb125c43 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-colorblind-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-colorblind-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-high-contrast-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-high-contrast-linux.png index c5c02fb32aa..0dbe2623717 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-high-contrast-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-high-contrast-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-linux.png index f82a1be25f5..b409a72a0ca 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-tritanopia-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-tritanopia-linux.png index cd50d271113..02dcb125c43 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-tritanopia-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Default-light-tritanopia-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-colorblind-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-colorblind-linux.png index 8c33f704f80..eb3aa0717fe 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-colorblind-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-colorblind-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-dimmed-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-dimmed-linux.png index e28973b7417..1ee0e54f7c3 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-dimmed-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-dimmed-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-high-contrast-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-high-contrast-linux.png index 9b9039f5076..3f4dae30d75 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-high-contrast-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-high-contrast-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-linux.png index 917e8babe7a..102e0e58e6e 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-tritanopia-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-tritanopia-linux.png index 917e8babe7a..eb3aa0717fe 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-tritanopia-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-dark-tritanopia-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-colorblind-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-colorblind-linux.png index 98f27f8aa1b..7270d86decd 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-colorblind-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-colorblind-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-high-contrast-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-high-contrast-linux.png index c5c02fb32aa..4dfcaaeee05 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-high-contrast-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-high-contrast-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-linux.png index f82a1be25f5..1abab13922e 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-tritanopia-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-tritanopia-linux.png index cd50d271113..7270d86decd 100644 Binary files a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-tritanopia-linux.png and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-Playground-light-tritanopia-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-colorblind-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-colorblind-linux.png new file mode 100644 index 00000000000..eb3aa0717fe Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-colorblind-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-dimmed-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-dimmed-linux.png new file mode 100644 index 00000000000..1ee0e54f7c3 Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-dimmed-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-high-contrast-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-high-contrast-linux.png new file mode 100644 index 00000000000..3f4dae30d75 Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-high-contrast-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-linux.png new file mode 100644 index 00000000000..102e0e58e6e Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-tritanopia-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-tritanopia-linux.png new file mode 100644 index 00000000000..eb3aa0717fe Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-dark-tritanopia-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-light-colorblind-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-light-colorblind-linux.png new file mode 100644 index 00000000000..7270d86decd Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-light-colorblind-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-light-high-contrast-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-light-high-contrast-linux.png new file mode 100644 index 00000000000..4dfcaaeee05 Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-light-high-contrast-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-light-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-light-linux.png new file mode 100644 index 00000000000..1abab13922e Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-light-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-light-tritanopia-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-light-tritanopia-linux.png new file mode 100644 index 00000000000..7270d86decd Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateAuto-light-tritanopia-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-colorblind-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-colorblind-linux.png new file mode 100644 index 00000000000..eb3aa0717fe Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-colorblind-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-dimmed-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-dimmed-linux.png new file mode 100644 index 00000000000..1ee0e54f7c3 Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-dimmed-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-high-contrast-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-high-contrast-linux.png new file mode 100644 index 00000000000..3f4dae30d75 Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-high-contrast-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-linux.png new file mode 100644 index 00000000000..102e0e58e6e Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-tritanopia-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-tritanopia-linux.png new file mode 100644 index 00000000000..eb3aa0717fe Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-dark-tritanopia-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-light-colorblind-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-light-colorblind-linux.png new file mode 100644 index 00000000000..7270d86decd Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-light-colorblind-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-light-high-contrast-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-light-high-contrast-linux.png new file mode 100644 index 00000000000..4dfcaaeee05 Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-light-high-contrast-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-light-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-light-linux.png new file mode 100644 index 00000000000..1abab13922e Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-light-linux.png differ diff --git a/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-light-tritanopia-linux.png b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-light-tritanopia-linux.png new file mode 100644 index 00000000000..7270d86decd Binary files /dev/null and b/.playwright/snapshots/components/LabelGroup.test.ts-snapshots/LabelGroup-TruncateToFive-light-tritanopia-linux.png differ diff --git a/e2e/components/LabelGroup.test.ts b/e2e/components/LabelGroup.test.ts index b4e48650df7..06a4b77d8a7 100644 --- a/e2e/components/LabelGroup.test.ts +++ b/e2e/components/LabelGroup.test.ts @@ -58,4 +58,74 @@ test.describe('LabelGroup', () => { }) } }) + + test.describe('Truncated to 5', () => { + for (const theme of themes) { + test.describe(theme, () => { + test('default @vrt', async ({page}) => { + await visit(page, { + id: 'components-labelgroup--playground', + globals: { + colorScheme: theme, + }, + }) + + // Default state + expect(await page.screenshot()).toMatchSnapshot(`LabelGroup.TruncateToFive.${theme}.png`) + }) + + test('axe @aat', async ({page}) => { + await visit(page, { + id: 'components-labelgroup-features--truncate-after-five', + globals: { + colorScheme: theme, + }, + }) + await expect(page).toHaveNoViolations() + }) + }) + } + }) + + test.describe('Truncated to fit', () => { + for (const theme of themes) { + test.describe(theme, () => { + test('default @vrt', async ({page}) => { + await visit(page, { + id: 'components-labelgroup--playground', + globals: { + colorScheme: theme, + }, + }) + + // Default state + expect(await page.screenshot()).toMatchSnapshot(`LabelGroup.TruncateAuto.${theme}.png`) + }) + + test('axe @aat', async ({page}) => { + await visit(page, { + id: 'components-labelgroup-features--truncate-auto', + globals: { + colorScheme: theme, + }, + }) + await expect(page).toHaveNoViolations() + }) + }) + } + }) + + test.describe('LabelGroup Interactions', () => { + test('inline overflow - focuses the first focusable token that was previously hidden', async ({page}) => { + await visit(page, { + id: 'components-labelgroup-features--truncate-auto-expand-inline-with-interactive-tokens', + globals: { + colorScheme: 'light', + }, + }) + await page.locator('button', {hasText: '+5'}).click() + + await expect(page.locator('button', {hasText: 'Twelve'})).toBeFocused() + }) + }) }) diff --git a/src/AnchoredOverlay/AnchoredOverlay.docs.json b/src/AnchoredOverlay/AnchoredOverlay.docs.json index a146edd08de..698f73ad698 100644 --- a/src/AnchoredOverlay/AnchoredOverlay.docs.json +++ b/src/AnchoredOverlay/AnchoredOverlay.docs.json @@ -53,6 +53,18 @@ "defaultValue": "'start'", "description": "" }, + { + "name": "alignmentOffset", + "type": "number", + "defaultValue": "4", + "description": "An additional offset, in pixels, to move the floating element from the aligning edge. Positive values move the floating element in the direction of center-alignment. Negative values move the floating element away from center-alignment. When align is `'center`, positive offsets move the floating element right (top or bottom anchor side) or down (left or right anchor side). If using outside positioning, or if `align` is set to `'center'`, this defaults to `0` instead of `4`." + }, + { + "name": "anchorOffset", + "type": "number", + "defaultValue": "4", + "description": "The number of pixels between the anchor edge and the floating element. Positive values move the floating element farther from the anchor element (for outside positioning) or further inside the anchor element (for inside positioning). Negative values have the opposite effect. If `side` is set to `'inside-center'`, this defaults to `0` instead of `4`." + }, { "name": "overlayProps", "type": "Partial", diff --git a/src/AnchoredOverlay/AnchoredOverlay.tsx b/src/AnchoredOverlay/AnchoredOverlay.tsx index 510ea7562fc..ed9b2643f22 100644 --- a/src/AnchoredOverlay/AnchoredOverlay.tsx +++ b/src/AnchoredOverlay/AnchoredOverlay.tsx @@ -80,7 +80,7 @@ interface AnchoredOverlayBaseProps extends Pick> + Partial> /** * An `AnchoredOverlay` provides an anchor that will open a floating overlay positioned relative to the anchor. @@ -101,6 +101,8 @@ export const AnchoredOverlay: React.FC { const anchorRef = useProvidedRefOrCreate(externalAnchorRef) const [overlayRef, updateOverlayRef] = useRenderForcingRef() @@ -140,6 +142,8 @@ export const AnchoredOverlay: React.FC