Skip to content

Commit 119e796

Browse files
authored
fix(DescriptionList): V5 - allow help text button popover to open via keyboard (#11547)
* fix(DescriptionList): V5 - allow help text button popover to open via keyboard * clean up branch switch
1 parent c132f12 commit 119e796

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

packages/react-core/src/components/DescriptionList/DescriptionListTermHelpTextButton.tsx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,33 @@ export const DescriptionListTermHelpTextButton: React.FunctionComponent<Descript
1313
children,
1414
className,
1515
...props
16-
}: DescriptionListTermHelpTextButtonProps) => (
17-
<span
18-
className={css(className, styles.descriptionListText, styles.modifiers.helpText)}
19-
role="button"
20-
type="button"
21-
tabIndex={0}
22-
{...props}
23-
>
24-
{children}
25-
</span>
26-
);
16+
}: DescriptionListTermHelpTextButtonProps) => {
17+
const helpTextRef = React.createRef<HTMLSpanElement>();
18+
19+
const handleKeys = (event: React.KeyboardEvent<HTMLSpanElement>) => {
20+
if (!helpTextRef.current || helpTextRef.current !== (event.target as HTMLElement)) {
21+
return;
22+
}
23+
24+
const key = event.key;
25+
if (key === 'Enter' || key === ' ') {
26+
event.preventDefault();
27+
helpTextRef.current.click();
28+
}
29+
};
30+
31+
return (
32+
<span
33+
ref={helpTextRef}
34+
className={css(className, styles.descriptionListText, styles.modifiers.helpText)}
35+
role="button"
36+
type="button"
37+
tabIndex={0}
38+
onKeyDown={(event) => handleKeys(event)}
39+
{...props}
40+
>
41+
{children}
42+
</span>
43+
);
44+
};
2745
DescriptionListTermHelpTextButton.displayName = 'DescriptionListTermHelpTextButton';

0 commit comments

Comments
 (0)