From 578a33d77e68695edd285cd03435d3190d025dfc Mon Sep 17 00:00:00 2001 From: Tyler Jones Date: Mon, 30 Dec 2024 10:18:56 -0500 Subject: [PATCH] ActionBar: Ensure overflow menu only exists if there is no space (#5476) * Ensure items in menu leave menu if there is space * Fixes initial check for if menu items should have overflow menu or not; adds new story * Add changeset * Fix stories file structure * Fix ID * Remove redundant check --- .changeset/thirty-apples-wave.md | 5 + e2e/components/drafts/ActionBar.test.ts | 6 +- .../ActionBar/ActionBar.examples.stories.tsx | 287 ++++++++++++++++++ .../react/src/ActionBar/ActionBar.stories.tsx | 268 ---------------- packages/react/src/ActionBar/ActionBar.tsx | 10 +- 5 files changed, 303 insertions(+), 273 deletions(-) create mode 100644 .changeset/thirty-apples-wave.md create mode 100644 packages/react/src/ActionBar/ActionBar.examples.stories.tsx diff --git a/.changeset/thirty-apples-wave.md b/.changeset/thirty-apples-wave.md new file mode 100644 index 00000000000..fc0f37d1810 --- /dev/null +++ b/.changeset/thirty-apples-wave.md @@ -0,0 +1,5 @@ +--- +"@primer/react": patch +--- + +ActionBar: Fixes issue where `ActionBar` overflow menu would persist even if it was no longer needed; allows overflow menu to appear on initial render if there is no space for all items. diff --git a/e2e/components/drafts/ActionBar.test.ts b/e2e/components/drafts/ActionBar.test.ts index 71d20bd6aa9..d8a183d0392 100644 --- a/e2e/components/drafts/ActionBar.test.ts +++ b/e2e/components/drafts/ActionBar.test.ts @@ -9,7 +9,7 @@ test.describe('ActionBar', () => { test.describe(theme, () => { test('default @vrt', async ({page}) => { await visit(page, { - id: 'experimental-components-actionbar--comment-box', + id: 'experimental-components-actionbar-examples--comment-box', globals: { colorScheme: theme, }, @@ -19,7 +19,7 @@ test.describe('ActionBar', () => { test('axe @aat', async ({page}) => { await visit(page, { - id: 'experimental-components-actionbar--comment-box', + id: 'experimental-components-actionbar-examples--comment-box', globals: { colorScheme: theme, }, @@ -35,7 +35,7 @@ test.describe('ActionBar', () => { test.describe(theme, () => { test('Overflow interaction @vrt', async ({page}) => { await visit(page, { - id: 'experimental-components-actionbar--comment-box', + id: 'experimental-components-actionbar-examples--comment-box', globals: { colorScheme: theme, }, diff --git a/packages/react/src/ActionBar/ActionBar.examples.stories.tsx b/packages/react/src/ActionBar/ActionBar.examples.stories.tsx new file mode 100644 index 00000000000..d80446b9d41 --- /dev/null +++ b/packages/react/src/ActionBar/ActionBar.examples.stories.tsx @@ -0,0 +1,287 @@ +import React from 'react' +import type {Meta} from '@storybook/react' +import ActionBar from '.' +import Text from '../Text' +import { + PencilIcon, + BoldIcon, + CodeIcon, + ItalicIcon, + SearchIcon, + LinkIcon, + FileAddedIcon, + HeadingIcon, + QuoteIcon, + ListUnorderedIcon, + ListOrderedIcon, + TasklistIcon, + ReplyIcon, + ThreeBarsIcon, +} from '@primer/octicons-react' +import {Box, Button, Avatar, ActionMenu, IconButton, ActionList, Textarea} from '..' +import {Dialog} from '../DialogV1' +import {Divider} from '../deprecated/ActionList/Divider' +import mockData from '../experimental/SelectPanel2/mock-story-data' + +export default { + title: 'Experimental/Components/ActionBar/Examples', +} as Meta + +export const TextLabels = () => ( + + + + + +) + +export const SmallActionBar = () => ( + + + + + + + + + +) + +type CommentBoxProps = {'aria-label': string} + +export const CommentBox = (props: CommentBoxProps) => { + const {'aria-label': ariaLabel} = props + const [value, setValue] = React.useState('') + const [isOpen, setIsOpen] = React.useState(false) + const buttonRef = React.useRef(null) + const toolBarLabel = `${ariaLabel ? ariaLabel : 'Comment box'} toolbar` + return ( + + + + + + + + + + + + + + + setIsOpen(true)} + icon={ReplyIcon} + aria-label="Saved Replies" + > + + + +