Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions packages/@react-spectrum/actionbar/docs/ActionBar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,47 @@ function Example({isEmphasized}: {isEmphasized?: boolean}) {
<Example isEmphasized />
</Flex>
```

### 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<Selection>(new Set(['photoshop']));

return (
<ActionBarContainer height={300} width="size-5000">
<ListView aria-label="ListView with action bar" selectionMode="multiple" selectedKeys={selectedKeys} onSelectionChange={setSelectedKeys}>
<Item key="photoshop">Adobe Photoshop</Item>
<Item key="illustrator">Adobe Illustrator</Item>
<Item key="xd">Adobe XD</Item>
</ListView>
<ActionBar
/*- begin highlight -*/
disabledKeys={['edit']}
/*- end highlight -*/
isEmphasized={true}
selectedItemCount={selectedKeys === 'all' ? 'all' : selectedKeys.size}
onAction={(key) => alert(`Performing ${key} action...`)}
onClearSelection={() => setSelectedKeys(new Set())}>
<Item key="edit">
<Edit />
<Text>Edit</Text>
</Item>
<Item key="copy">
<Copy />
<Text>Copy</Text>
</Item>
<Item key="delete">
<Delete />
<Text>Delete</Text>
</Item>
</ActionBar>
</ActionBarContainer>
);
}

<Example />
```
4 changes: 3 additions & 1 deletion packages/@react-spectrum/actionbar/src/ActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ function ActionBarInner<T>(props: ActionBarInnerProps<T>, ref: Ref<HTMLDivElemen
selectedItemCount,
isOpen,
buttonLabelBehavior = 'collapse',
items
items,
disabledKeys
} = props;

let {styleProps} = useStyleProps(props);
Expand Down Expand Up @@ -113,6 +114,7 @@ function ActionBarInner<T>(props: ActionBarInnerProps<T>, ref: Ref<HTMLDivElemen
overflowMode="collapse"
buttonLabelBehavior={buttonLabelBehavior}
onAction={onAction}
disabledKeys={disabledKeys}
UNSAFE_className={classNames(styles, 'react-spectrum-ActionBar-actionGroup')}>
{children}
</ActionGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,12 @@ function FullWidth(props) {
let viewport = useViewportSize();
return <Example tableWidth="100vw" containerHeight={viewport.height} isQuiet {...props} />;
}

export const DisabledKeysStory: ActionBarStory = {
...Default,
render: (args) => <DisabledKeys {...args} />
};

function DisabledKeys(props) {
return <Example disabledKeys={['edit']} {...props} />;
}
13 changes: 13 additions & 0 deletions packages/@react-spectrum/actionbar/test/ActionBar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,17 @@ describe('ActionBar', () => {

expect(onAction).toHaveBeenCalledWith('edit');
});

it('should respect disabledKeys when passed in', async () => {
let tree = render(<Provider theme={theme}><Example disabledKeys={['edit']} /></Provider>);
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();
});
});