Skip to content

Commit a3f7ea9

Browse files
authored
fix(AnchoredOverlay): Omit aria-label and aria-labelledby from renderAnchor props (#6973)
1 parent a15faef commit a3f7ea9

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

.changeset/poor-ducks-attack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
fix(AnchoredOverlay): Omit aria-label and aria-labelledby from renderAnchor props

packages/react/src/AnchoredOverlay/AnchoredOverlay.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ interface AnchoredOverlayPropsWithAnchor {
2020
* A custom function component used to render the anchor element.
2121
* Will receive the selected text as `children` prop when an item is activated.
2222
*/
23-
renderAnchor: <T extends React.HTMLAttributes<HTMLElement>>(props: T) => JSX.Element
23+
renderAnchor: <T extends Omit<React.HTMLAttributes<HTMLElement>, 'aria-label' | 'aria-labelledby'>>(
24+
props: T,
25+
) => JSX.Element
2426

2527
/**
2628
* An override to the internal ref that will be spread on to the renderAnchor
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {InfoIcon} from '@primer/octicons-react'
2+
import {AnchoredOverlay, IconButton} from '..'
3+
4+
export function itemWithIconElements() {
5+
return (
6+
<AnchoredOverlay open={true} renderAnchor={props => <IconButton {...props} icon={InfoIcon} aria-label="Info" />}>
7+
<p>GitHub</p>
8+
</AnchoredOverlay>
9+
)
10+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ export const HeightInitialWithUnderflowingItemsAfterFetch = () => {
140140
<FormControl>
141141
<FormControl.Label>Labels</FormControl.Label>
142142
<SelectPanel
143-
renderAnchor={({children, 'aria-labelledby': ariaLabelledBy, ...anchorProps}) => (
144-
<Button trailingAction={TriangleDownIcon} aria-labelledby={` ${ariaLabelledBy}`} {...anchorProps}>
143+
renderAnchor={({children, ...anchorProps}) => (
144+
<Button trailingAction={TriangleDownIcon} {...anchorProps}>
145145
{children}
146146
</Button>
147147
)}
@@ -172,8 +172,8 @@ export const AboveTallBody = () => {
172172
<FormControl>
173173
<FormControl.Label>Labels</FormControl.Label>
174174
<SelectPanel
175-
renderAnchor={({children, 'aria-labelledby': ariaLabelledBy, ...anchorProps}) => (
176-
<Button trailingAction={TriangleDownIcon} aria-labelledby={` ${ariaLabelledBy}`} {...anchorProps}>
175+
renderAnchor={({children, ...anchorProps}) => (
176+
<Button trailingAction={TriangleDownIcon} {...anchorProps}>
177177
{children}
178178
</Button>
179179
)}

packages/react/src/SelectPanel/SelectPanel.features.stories.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,8 @@ export const AsyncFetch: StoryObj<SelectPanelProps> = {
582582
<SelectPanel
583583
title="Select labels"
584584
subtitle="Use labels to organize issues and pull requests"
585-
renderAnchor={({children, 'aria-labelledby': ariaLabelledBy, ...anchorProps}) => (
586-
<Button
587-
trailingAction={TriangleDownIcon}
588-
aria-labelledby={` ${ariaLabelledBy}`}
589-
{...anchorProps}
590-
aria-haspopup="dialog"
591-
>
585+
renderAnchor={({children, ...anchorProps}) => (
586+
<Button trailingAction={TriangleDownIcon} {...anchorProps} aria-haspopup="dialog">
592587
{children ?? 'Select Labels'}
593588
</Button>
594589
)}
@@ -656,8 +651,8 @@ export const CustomisedNoInitialItems = () => {
656651
<ToggleSwitch onClick={onClick} checked={isError} aria-labelledby="toggle" />
657652
<SelectPanel
658653
title="Set projects"
659-
renderAnchor={({children, 'aria-labelledby': ariaLabelledBy, ...anchorProps}) => (
660-
<Button trailingAction={TriangleDownIcon} aria-labelledby={` ${ariaLabelledBy}`} {...anchorProps}>
654+
renderAnchor={({children, ...anchorProps}) => (
655+
<Button trailingAction={TriangleDownIcon} {...anchorProps}>
661656
{children ?? 'Select Labels'}
662657
</Button>
663658
)}
@@ -709,13 +704,8 @@ export const CustomisedNoResults: StoryObj<typeof SelectPanel> = {
709704
<SelectPanel
710705
title="Select labels"
711706
subtitle="Use labels to organize issues and pull requests"
712-
renderAnchor={({children, 'aria-labelledby': ariaLabelledBy, ...anchorProps}) => (
713-
<Button
714-
trailingAction={TriangleDownIcon}
715-
aria-labelledby={` ${ariaLabelledBy}`}
716-
{...anchorProps}
717-
aria-haspopup="dialog"
718-
>
707+
renderAnchor={({children, ...anchorProps}) => (
708+
<Button trailingAction={TriangleDownIcon} {...anchorProps} aria-haspopup="dialog">
719709
{children ?? 'Select Labels'}
720710
</Button>
721711
)}

0 commit comments

Comments
 (0)