From 64c9dbe6ba330f14ff51e43535f5bd9ed0b85ac0 Mon Sep 17 00:00:00 2001 From: Grant Russell Date: Wed, 25 Sep 2024 19:36:57 -0600 Subject: [PATCH 1/2] pass through disabledKeys to ActionGroup --- .../actionbar/docs/ActionBar.mdx | 44 +++++++++++++++++++ .../actionbar/src/ActionBar.tsx | 4 +- .../actionbar/stories/ActionBar.stories.tsx | 9 ++++ .../actionbar/test/ActionBar.test.js | 13 ++++++ 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/packages/@react-spectrum/actionbar/docs/ActionBar.mdx b/packages/@react-spectrum/actionbar/docs/ActionBar.mdx index 44d06f4d27b..c0f2be34d63 100644 --- a/packages/@react-spectrum/actionbar/docs/ActionBar.mdx +++ b/packages/@react-spectrum/actionbar/docs/ActionBar.mdx @@ -248,3 +248,47 @@ function Example({isEmphasized}: {isEmphasized?: boolean}) { ``` + +### isDisabled +To disable individual items, a list of disabledKeys can be provided. + +```tsx example +import type {Selection} from '@adobe/react-spectrum'; + +function Example() { + let [selectedKeys, setSelectedKeys] = React.useState(new Set(['photoshop'])); + + return ( + + + Adobe Photoshop + Adobe Illustrator + Adobe XD + + alert(`Performing ${key} action...`)} + onClearSelection={() => setSelectedKeys(new Set())}> + + + Edit + + + + Copy + + + + Delete + + + + ); +} + + +``` \ No newline at end of file diff --git a/packages/@react-spectrum/actionbar/src/ActionBar.tsx b/packages/@react-spectrum/actionbar/src/ActionBar.tsx index 35c32665c43..594f353591f 100644 --- a/packages/@react-spectrum/actionbar/src/ActionBar.tsx +++ b/packages/@react-spectrum/actionbar/src/ActionBar.tsx @@ -59,7 +59,8 @@ function ActionBarInner(props: ActionBarInnerProps, ref: Ref(props: ActionBarInnerProps, ref: Ref {children} diff --git a/packages/@react-spectrum/actionbar/stories/ActionBar.stories.tsx b/packages/@react-spectrum/actionbar/stories/ActionBar.stories.tsx index 2c8dc630e8d..c7f3e2fb686 100644 --- a/packages/@react-spectrum/actionbar/stories/ActionBar.stories.tsx +++ b/packages/@react-spectrum/actionbar/stories/ActionBar.stories.tsx @@ -62,3 +62,12 @@ function FullWidth(props) { let viewport = useViewportSize(); return ; } + +export const DisabledKeysStory: ActionBarStory = { + ...Default, + render: (args) => +} + +function DisabledKeys(props) { + return +} diff --git a/packages/@react-spectrum/actionbar/test/ActionBar.test.js b/packages/@react-spectrum/actionbar/test/ActionBar.test.js index 1e9f4b3df06..c843963db0d 100644 --- a/packages/@react-spectrum/actionbar/test/ActionBar.test.js +++ b/packages/@react-spectrum/actionbar/test/ActionBar.test.js @@ -285,4 +285,17 @@ describe('ActionBar', () => { expect(onAction).toHaveBeenCalledWith('edit'); }); + + it('should respect disabledKeys when passed in', async () => { + let tree = render(); + act(() => {jest.runAllTimers();}); + + let table = tree.getByRole('grid'); + let rows = within(table).getAllByRole('row'); + + await user.click(rows[1]); + + expect(within(tree.getByRole('toolbar')).getAllByRole('button')[0]).toBeDisabled(); + expect(within(tree.getByRole('toolbar')).getAllByRole('button')[1]).not.toBeDisabled(); + }) }); From a9c174a32511f37c4d1f6f9fea4e0585ec7f18d4 Mon Sep 17 00:00:00 2001 From: Grant Russell Date: Wed, 25 Sep 2024 19:51:10 -0600 Subject: [PATCH 2/2] fix linting issues --- .../@react-spectrum/actionbar/stories/ActionBar.stories.tsx | 4 ++-- packages/@react-spectrum/actionbar/test/ActionBar.test.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/@react-spectrum/actionbar/stories/ActionBar.stories.tsx b/packages/@react-spectrum/actionbar/stories/ActionBar.stories.tsx index c7f3e2fb686..be67457cacf 100644 --- a/packages/@react-spectrum/actionbar/stories/ActionBar.stories.tsx +++ b/packages/@react-spectrum/actionbar/stories/ActionBar.stories.tsx @@ -66,8 +66,8 @@ function FullWidth(props) { export const DisabledKeysStory: ActionBarStory = { ...Default, render: (args) => -} +}; function DisabledKeys(props) { - return + return ; } diff --git a/packages/@react-spectrum/actionbar/test/ActionBar.test.js b/packages/@react-spectrum/actionbar/test/ActionBar.test.js index c843963db0d..dccdc80929b 100644 --- a/packages/@react-spectrum/actionbar/test/ActionBar.test.js +++ b/packages/@react-spectrum/actionbar/test/ActionBar.test.js @@ -297,5 +297,5 @@ describe('ActionBar', () => { expect(within(tree.getByRole('toolbar')).getAllByRole('button')[0]).toBeDisabled(); expect(within(tree.getByRole('toolbar')).getAllByRole('button')[1]).not.toBeDisabled(); - }) + }); });