Debian Codegraph @

node/@patternfly/react-core/src/components/Nav/NavGroup.tsx

raw
1 import styles from '@patternfly/react-styles/css/components/Nav/nav';
2 import { css } from '@patternfly/react-styles';
3 import { useSSRSafeId } from '../../helpers';
4
5 export interface NavGroupProps extends React.HTMLProps<HTMLDivElement> {
6 /** Title shown for the group */
7 title?: string;
8 /** Anything that can be rendered inside of the group */
9 children?: React.ReactNode;
10 /** Additional classes added to the container */
11 className?: string;
12 /** Identifier to use for the section aria label */
13 id?: string;
14 }
15
16 export const NavGroup: React.FunctionComponent<NavGroupProps> = ({
17 title,
18 children = null,
19 className = '',
20 id: idProp,
21 ...props
22 }: NavGroupProps) => {
23 const generatedId = useSSRSafeId();
24 const id = idProp ?? generatedId;
25 if (!title && !props['aria-label']) {
26 // eslint-disable-next-line no-console
27 console.warn("For accessibility reasons an aria-label should be specified on nav groups if a title isn't");
28 }
29
30 const labelledBy = title ? id : undefined;
31
32 return (
33 <section className={css(styles.navSection, className)} aria-labelledby={labelledBy} {...props}>
34 {title && (
35 <h2 className={css(styles.navSectionTitle)} id={id}>
36 {title}
37 </h2>
38 )}
39 <ul className={css(styles.navList, className)} role="list">
40 {children}
41 </ul>
42 </section>
43 );
44 };
45 NavGroup.displayName = 'NavGroup';