Skip to content

Commit b064ad4

Browse files
committed
Add disabled prop to ActionBar
1 parent 65a197b commit b064ad4

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

packages/react/src/ActionBar/ActionBar.docs.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
"type": "string",
7676
"defaultValue": "",
7777
"description": "Use an aria label to describe the functionality of the button. Please refer to [our guidance on alt text](https://primer.style/guides/accessibility/alternative-text-for-images) for tips on writing good alternative text."
78+
},
79+
{
80+
"name": "disabled",
81+
"type": "boolean",
82+
"defaultValue": "",
83+
"description": "Provides a disabled state for the button. The button will remain focusable, and have `aria-disabled` applied."
7884
}
7985
],
8086
"passthrough": {

packages/react/src/ActionBar/ActionBar.examples.stories.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ export const SmallActionBar = () => (
4747
</ActionBar>
4848
)
4949

50+
export const WithDisabledItems = () => (
51+
<ActionBar aria-label="Toolbar">
52+
<ActionBar.IconButton icon={BoldIcon} aria-label="Bold"></ActionBar.IconButton>
53+
<ActionBar.IconButton icon={ItalicIcon} aria-label="Italic"></ActionBar.IconButton>
54+
<ActionBar.IconButton icon={CodeIcon} aria-label="Code"></ActionBar.IconButton>
55+
<ActionBar.IconButton icon={LinkIcon} aria-label="Link"></ActionBar.IconButton>
56+
<ActionBar.Divider />
57+
<ActionBar.IconButton disabled icon={FileAddedIcon} aria-label="File Added"></ActionBar.IconButton>
58+
<ActionBar.IconButton disabled icon={SearchIcon} aria-label="Search"></ActionBar.IconButton>
59+
<ActionBar.IconButton disabled icon={QuoteIcon} aria-label="Insert Quote"></ActionBar.IconButton>
60+
<ActionBar.IconButton icon={ListUnorderedIcon} aria-label="Unordered List"></ActionBar.IconButton>
61+
<ActionBar.IconButton icon={ListOrderedIcon} aria-label="Ordered List"></ActionBar.IconButton>
62+
<ActionBar.IconButton icon={TasklistIcon} aria-label="Task List"></ActionBar.IconButton>
63+
</ActionBar>
64+
)
65+
5066
type CommentBoxProps = {'aria-label': string}
5167

5268
export const CommentBox = (props: CommentBoxProps) => {

packages/react/src/ActionBar/ActionBar.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export type ActionBarProps = {
4646
className?: string
4747
} & A11yProps
4848

49-
export type ActionBarIconButtonProps = IconButtonProps
49+
export type ActionBarIconButtonProps = {disabled?: boolean} & IconButtonProps
5050

5151
const MORE_BTN_WIDTH = 86
5252

@@ -215,7 +215,13 @@ export const ActionBar: React.FC<React.PropsWithChildren<ActionBarProps>> = prop
215215
if (menuItem.type === ActionList.Divider) {
216216
return <ActionList.Divider key={index} />
217217
} else {
218-
const {children: menuItemChildren, onClick, icon: Icon, 'aria-label': ariaLabel} = menuItem.props
218+
const {
219+
children: menuItemChildren,
220+
onClick,
221+
icon: Icon,
222+
'aria-label': ariaLabel,
223+
disabled,
224+
} = menuItem.props
219225
return (
220226
<ActionList.Item
221227
key={menuItemChildren}
@@ -224,6 +230,7 @@ export const ActionBar: React.FC<React.PropsWithChildren<ActionBarProps>> = prop
224230
focusOnMoreMenuBtn()
225231
typeof onClick === 'function' && onClick(event)
226232
}}
233+
disabled={disabled}
227234
>
228235
{Icon ? (
229236
<ActionList.LeadingVisual>
@@ -254,7 +261,7 @@ export const ActionBarIconButton = forwardRef((props: ActionBarIconButtonProps,
254261
const domRect = (ref as MutableRefObject<HTMLElement>).current.getBoundingClientRect()
255262
setChildrenWidth({text, width: domRect.width})
256263
}, [ref, setChildrenWidth])
257-
return <IconButton ref={ref} size={size} {...props} variant="invisible" />
264+
return <IconButton aria-disabled={props.disabled} ref={ref} size={size} {...props} variant="invisible" />
258265
})
259266

260267
export const VerticalDivider = () => {

0 commit comments

Comments
 (0)