import { createRef } from 'react'; import styles from '@patternfly/react-styles/css/components/DescriptionList/description-list'; import { css } from '@patternfly/react-styles'; export interface DescriptionListTermHelpTextButtonProps extends React.HTMLProps { /** Anything that can be rendered inside of list term */ children: React.ReactNode; /** Additional classes added to the DescriptionListTerm */ className?: string; } export const DescriptionListTermHelpTextButton: React.FunctionComponent = ({ children, className, ...props }: DescriptionListTermHelpTextButtonProps) => { const helpTextRef = createRef(); const handleKeys = (event: React.KeyboardEvent) => { if (!helpTextRef.current || helpTextRef.current !== (event.target as HTMLElement)) { return; } const key = event.key; if (key === 'Enter' || key === ' ') { event.preventDefault(); helpTextRef.current.click(); } }; return ( handleKeys(event)} {...props} > {children} ); }; DescriptionListTermHelpTextButton.displayName = 'DescriptionListTermHelpTextButton';