Skip to content

Commit bfdbb80

Browse files
committed
Icon button fixes removes iconLabel and adds aria-label to the type
1 parent 842018e commit bfdbb80

File tree

4 files changed

+12
-25
lines changed

4 files changed

+12
-25
lines changed

docs/content/IconButton.mdx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,9 @@ A separate component called `IconButton` is used if the action shows only an ico
2828

2929
```jsx live drafts
3030
<>
31-
<IconButton icon={SearchIcon} size="small">
32-
Search
33-
</IconButton>
34-
<IconButton sx={{ml: 2}} icon={SearchIcon}>
35-
Search
36-
</IconButton>
37-
<IconButton sx={{ml: 2}} icon={SearchIcon} size="large">
38-
Search
39-
</IconButton>
31+
<IconButton aria-label="Search" icon={SearchIcon} size="small" />
32+
<IconButton aria-label="Search" sx={{ml: 2}} icon={SearchIcon} />
33+
<IconButton aria-label="Search" sx={{ml: 2}} icon={SearchIcon} size="large" />
4034
</>
4135
```
4236

src/Button/Button2.stories.tsx renamed to src/Button/Button.stories.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {XIcon, SearchIcon, EyeIcon, EyeClosedIcon, TriangleDownIcon, TriangleRig
66
import Box from '../Box'
77

88
export default {
9-
title: 'Composite components/Button2',
9+
title: 'Composite components/Button',
1010

1111
decorators: [
1212
Story => {
@@ -69,19 +69,19 @@ export const iconButton = ({...args}: ButtonProps) => {
6969
return (
7070
<>
7171
<Box mb={2}>
72-
<IconButton icon={XIcon} iconLabel="Close" {...args} />
72+
<IconButton icon={XIcon} aria-label="Close" {...args} />
7373
</Box>
7474
<Box mb={2}>
75-
<IconButton icon={XIcon} iconLabel="Close" {...args} variant="invisible" sx={{mt: 2}} />
75+
<IconButton icon={XIcon} aria-label="Close" {...args} variant="invisible" sx={{mt: 2}} />
7676
</Box>
7777
<Box mb={2}>
78-
<IconButton icon={XIcon} iconLabel="Close" {...args} variant="danger" />
78+
<IconButton icon={XIcon} aria-label="Close" {...args} variant="danger" />
7979
</Box>
8080
<Box mb={2}>
81-
<IconButton icon={XIcon} iconLabel="Close" {...args} variant="primary" />
81+
<IconButton icon={XIcon} aria-label="Close" {...args} variant="primary" />
8282
</Box>
8383
<Box mb={2}>
84-
<IconButton icon={XIcon} iconLabel="Close" {...args} variant="outline" />
84+
<IconButton icon={XIcon} aria-label="Close" {...args} variant="outline" />
8585
</Box>
8686
</>
8787
)

src/Button/IconButton.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import {useTheme} from '../ThemeProvider'
44
import Box from '../Box'
55
import {IconButtonProps, StyledButton} from './types'
66
import {getBaseStyles, getSizeStyles, getVariantStyles} from './styles'
7-
import {useSSRSafeId} from '@react-aria/ssr'
87

98
const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>((props, forwardedRef): JSX.Element => {
10-
const {variant = 'default', size = 'medium', sx: sxProp = {}, icon: Icon, iconLabel, ...rest} = props
11-
const iconLabelId = useSSRSafeId()
9+
const {variant = 'default', size = 'medium', sx: sxProp = {}, icon: Icon, ...rest} = props
1210
const {theme} = useTheme()
1311
const sxStyles = merge.all([
1412
getBaseStyles(theme),
@@ -17,12 +15,7 @@ const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>((props, forwar
1715
sxProp as SxProp
1816
])
1917
return (
20-
<StyledButton aria-labelledby={iconLabelId} sx={sxStyles} {...rest} ref={forwardedRef}>
21-
{iconLabel && (
22-
<span id={iconLabelId} hidden={true}>
23-
{iconLabel}
24-
</span>
25-
)}
18+
<StyledButton sx={sxStyles} {...rest} ref={forwardedRef}>
2619
<Box as="span" sx={{display: 'inline-block'}}>
2720
<Icon />
2821
</Box>

src/Button/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export type IconButtonProps = {
4545
* This is to be used if it is an icon-only button. Will make text visually hidden
4646
*/
4747
icon: React.FunctionComponent<IconProps>
48-
iconLabel: string
48+
'aria-label': string
4949
} & ButtonBaseProps
5050

5151
// adopted from React.AnchorHTMLAttributes

0 commit comments

Comments
 (0)