Skip to content

Commit f3581fb

Browse files
feat(popover): changes after review
1 parent caf47c0 commit f3581fb

File tree

4 files changed

+7
-178
lines changed

4 files changed

+7
-178
lines changed

apps/website/src/routes/docs/headless/(components)/popover/examples.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const MainExample = component$(() => {
1010
<PopoverContent>
1111
<div class="p-4 bg-gray-500">Hi, I'm the content</div>
1212
</PopoverContent>
13-
<PopoverTrigger ariaLabel="Freund">Click on me</PopoverTrigger>
13+
<PopoverTrigger aria-label="Freund">Click on me</PopoverTrigger>
1414
</Popover>
1515
</div>
1616
<div q:slot="codeExample">
@@ -30,7 +30,7 @@ export const Example1 = component$(() => {
3030
Hi, I'm the content, but now on top
3131
</div>
3232
</PopoverContent>
33-
<PopoverTrigger ariaLabel="no-click-friend">
33+
<PopoverTrigger aria-label="no-click-friend">
3434
Click on me
3535
</PopoverTrigger>
3636
</Popover>

packages/kit-headless/src/components/popover/popover-trigger.tsx

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,22 @@
11
import {
22
$,
3+
QwikIntrinsicElements,
34
Slot,
45
component$,
56
useContext,
67
useSignal,
7-
useStore,
88
useStylesScoped$,
9-
useTask$,
109
useVisibleTask$,
1110
} from '@builder.io/qwik';
12-
import {
13-
ExtendedPropsByAriaAttribute,
14-
QwikUiAreaAttributesFunctionReturnType,
15-
getAriaAttributes,
16-
} from '../../utils';
11+
import { AriaKeysOnlyKebab } from '../../utils';
1712
import { PopoverContext } from './popover-context';
1813
import styles from './popover-trigger.css?inline';
1914

2015
export const PopoverTrigger = component$(
21-
(props: ExtendedPropsByAriaAttribute<'span'>) => {
16+
(props: AriaKeysOnlyKebab<QwikIntrinsicElements['span']>) => {
2217
const ref = useSignal<HTMLElement>();
2318
const contextService = useContext(PopoverContext);
2419
useStylesScoped$(styles);
25-
const ariaAttributesStore = useStore<
26-
Partial<QwikUiAreaAttributesFunctionReturnType<'span'>>
27-
>({
28-
lastKey: undefined,
29-
ariaAttributes: undefined,
30-
});
31-
useTask$(({ track }) => {
32-
track(() => ({ ...props }));
33-
const { lastKey, ariaAttributes } = getAriaAttributes<'span'>(
34-
props,
35-
ariaAttributesStore.lastKey
36-
);
37-
ariaAttributesStore.ariaAttributes = ariaAttributes;
38-
ariaAttributesStore.lastKey = lastKey;
39-
});
4020

4121
useVisibleTask$(() => {
4222
contextService.setTriggerRef$(ref);
@@ -48,7 +28,7 @@ export const PopoverTrigger = component$(
4828
return (
4929
<span
5030
ref={ref}
51-
{...ariaAttributesStore.ariaAttributes}
31+
{...props}
5232
role="button"
5333
class="popover-trigger"
5434
onMouseOver$={

packages/kit-headless/src/utils/aria-attributes-helper.ts

Lines changed: 0 additions & 85 deletions
This file was deleted.
Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,3 @@
1-
import { QwikIntrinsicElements } from '@builder.io/qwik';
2-
// import { propertiesOf } from 'ts-reflection';
3-
4-
type ToCamelCase<S extends string> = S extends `${infer Head}-${infer Tail}`
5-
? `${Head}${Capitalize<ToCamelCase<Tail>>}`
6-
: S;
7-
8-
type StringValueKeys<T> = {
9-
[K in keyof T]: T[K] extends string ? K : never;
10-
}[keyof T];
11-
12-
export type AnyKeyOfQwikIntrinsicElement<K extends string> = StringValueKeys<
13-
QwikIntrinsicElements[K]
14-
>;
15-
16-
type AriaKeysOnlyCamel<T> = {
17-
[K in keyof T as K extends `aria-${string}` ? ToCamelCase<K> : never]: T[K];
18-
};
19-
20-
type AriaKeysOnlySnake<T> = {
1+
export type AriaKeysOnlyKebab<T> = {
212
[K in keyof T as K extends `aria-${string}` ? K : never]: T[K];
223
};
23-
24-
export type QwikAriaAttributeCamelCaseElement<K extends string> =
25-
K extends string ? AriaKeysOnlyCamel<QwikIntrinsicElements[K]> : undefined;
26-
27-
export type QwikIntrinsicAriaAttributes<K extends string> = K extends string
28-
? AriaKeysOnlySnake<QwikIntrinsicElements[K]>
29-
: undefined;
30-
31-
export type ExtendedPropsByAriaAttribute<
32-
K extends string,
33-
T = undefined
34-
> = T extends object
35-
? K extends undefined
36-
? T
37-
: T & QwikAriaAttributeCamelCaseElement<K extends string ? K : undefined>
38-
: T extends undefined
39-
? K extends undefined
40-
? object
41-
: QwikAriaAttributeCamelCaseElement<K extends string ? K : undefined>
42-
: never;
43-
44-
export type QwikUiAreaAttributesFunctionType<K extends string> = (
45-
ariaAttributes?: Partial<QwikAriaAttributeCamelCaseElement<K>>,
46-
lastKey?: string
47-
) => {
48-
lastKey: string;
49-
ariaAttributes: Partial<QwikIntrinsicAriaAttributes<K>>;
50-
};
51-
52-
export type QwikUiAreaAttributesFunctionReturnType<K extends string> =
53-
ReturnType<QwikUiAreaAttributesFunctionType<K>>;
54-
55-
export function isKeyOfQwikCamelAriaAttributes(
56-
key: string
57-
): key is keyof QwikAriaAttributeCamelCaseElement<string> {
58-
// const ariaAttributeKeys = propertiesOf<QwikUiAriaAttributesKebab>();
59-
// return ariaAttributeKeys.includes(key as keyof QwikUiAriaAttributesKebab);
60-
return key.startsWith('aria') && key.indexOf('-') === -1;
61-
}
62-
63-
export function isKeyOfQwikIntrinsicAriaAttributes(
64-
key: string
65-
): key is keyof QwikIntrinsicAriaAttributes<string> {
66-
// const ariaAttributeKeys = propertiesOf<AriaAttributes>();
67-
// return ariaAttributeKeys.includes(key as keyof AriaAttributes);
68-
return key.startsWith('aria') && key.indexOf('-') > -1;
69-
}

0 commit comments

Comments
 (0)