Debian Codegraph @

node/@patternfly/react-core/src/components/DescriptionList/DescriptionListTermHelpTextButton.tsx

raw
1 import { createRef } from 'react';
2 import styles from '@patternfly/react-styles/css/components/DescriptionList/description-list';
3 import { css } from '@patternfly/react-styles';
4
5 export interface DescriptionListTermHelpTextButtonProps extends React.HTMLProps<HTMLSpanElement> {
6 /** Anything that can be rendered inside of list term */
7 children: React.ReactNode;
8 /** Additional classes added to the DescriptionListTerm */
9 className?: string;
10 }
11
12 export const DescriptionListTermHelpTextButton: React.FunctionComponent<DescriptionListTermHelpTextButtonProps> = ({
13 children,
14 className,
15 ...props
16 }: DescriptionListTermHelpTextButtonProps) => {
17 const helpTextRef = 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 };
45 DescriptionListTermHelpTextButton.displayName = 'DescriptionListTermHelpTextButton';