Skip to content

Commit 8ca790d

Browse files
committed
feat(primitives): add level prop for Popover.Title component
1 parent 1ae8a1e commit 8ca790d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/primitives/src/components/popover/popover-title/popover-title.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PopoverContext } from '../popover-context';
99
* This component is based on the `h2` element.
1010
*/
1111
export const PopoverTitle = component$<PopoverTitleProps>((props) => {
12-
const { as, id, visuallyHidden, style, ...others } = props;
12+
const { as, id, level = '2', visuallyHidden, style, ...others } = props;
1313

1414
const { titleId } = useContext(PopoverContext);
1515

@@ -25,14 +25,15 @@ export const PopoverTitle = component$<PopoverTitleProps>((props) => {
2525
});
2626
});
2727

28-
const Component = as || 'h2';
28+
const Component = as || (`h${level}` as const);
2929

3030
return (
3131
<Component
3232
id={titleId.value}
3333
data-qwik-primitives-popover-title=""
3434
data-scope="popover"
3535
data-part="title"
36+
data-level={level}
3637
style={{
3738
...(visuallyHidden && visuallyHiddenStyle),
3839
...style,

packages/primitives/src/components/popover/popover-title/popover-title.types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export interface PopoverTitleProps extends PropsOf<'h2'> {
88
*/
99
as?: FunctionComponent;
1010

11+
/**
12+
* The level of the title, determines which tag will be used (h1-h6).
13+
* @default "2"
14+
*/
15+
level?: '1' | '2' | '3' | '4' | '5' | '6';
16+
1117
/**
1218
* When `true`, title will be hide from the screen in an accessible way.
1319
*/

0 commit comments

Comments
 (0)