Skip to content

Commit 80f652d

Browse files
authored
Merge pull request #363 from Zankel-Engineering/feature/accessibility
2 parents 51ed4b0 + a6cdc31 commit 80f652d

File tree

10 files changed

+2570
-2567
lines changed

10 files changed

+2570
-2567
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> Click on me </PopoverTrigger>
13+
<PopoverTrigger>Click on me</PopoverTrigger>
1414
</Popover>
1515
</div>
1616
<div q:slot="codeExample">
@@ -28,7 +28,7 @@ export const Example1 = component$(() => {
2828
<PopoverContent>
2929
<div class="p-4 bg-gray-500">Hi, I'm the content, but now on top</div>
3030
</PopoverContent>
31-
<PopoverTrigger> Click on me </PopoverTrigger>
31+
<PopoverTrigger>Click on me</PopoverTrigger>
3232
</Popover>
3333
</div>
3434
<div q:slot="codeExample">

apps/website/src/routes/docs/tailwind/(components)/popover/index.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ export default component$(() => {
2626
<Box />
2727
</PopoverContent>
2828
<PopoverTrigger>
29-
<Button onClick$={() => console.log('here')}>
30-
Offset and position
31-
</Button>
29+
<Button onClick$={() => console.log('here')}>Offset and position</Button>
3230
</PopoverTrigger>
3331
</Popover>
3432

@@ -88,8 +86,8 @@ export default component$(() => {
8886

8987
<h1 class="mt-8">DISABLE CLICK OUTSIDE</h1>
9088
<p>
91-
Popovers are not closed when click outside but they can be closed
92-
clicking their own trigger button only
89+
Popovers are not closed when click outside but they can be closed clicking their
90+
own trigger button only
9391
</p>
9492

9593
<div class="flex flex-col gap-2">
@@ -140,8 +138,8 @@ export default component$(() => {
140138
<code>Current state: {JSON.stringify(controlledPopover.value)}</code>
141139
</div>
142140
<p>
143-
The popover can be closed clicking outside or clicking the CLOSE button
144-
inside the popover
141+
The popover can be closed clicking outside or clicking the CLOSE button inside the
142+
popover
145143
</p>
146144
<p>the onUpdate$ callback allows you to sync local and popover states</p>
147145

@@ -156,16 +154,12 @@ export default component$(() => {
156154
<Card>
157155
<CardBody>
158156
<CardTitle>title</CardTitle>
159-
<Button onClick$={() => (controlledPopover.value = false)}>
160-
CLOSE ME
161-
</Button>
157+
<Button onClick$={() => (controlledPopover.value = false)}>CLOSE ME</Button>
162158
</CardBody>
163159
</Card>
164160
</PopoverContent>
165161
<PopoverTrigger>
166-
<Button onClick$={() => console.log('clicked')}>
167-
TOGGLE POPOVER
168-
</Button>
162+
<Button onClick$={() => console.log('clicked')}>TOGGLE POPOVER</Button>
169163
</PopoverTrigger>
170164
</Popover>
171165

cla-signs/v1/cla.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,14 @@
288288
"repoId": 545159943,
289289
"pullRequestNo": 340
290290
},
291+
{
292+
"name": "Zankel-Engineering",
293+
"id": 43412711,
294+
"comment_id": 1802088836,
295+
"created_at": "2023-07-15T17:00:00Z",
296+
"repoId": 666652720,
297+
"pullRequestNo": 363
298+
},
291299
{
292300
"name": "balaji-sivasakthi",
293301
"id": 65065614,
@@ -305,4 +313,4 @@
305313
"pullRequestNo": 385
306314
}
307315
]
308-
}
316+
}

packages/kit-headless/CHANGELOG.md

Lines changed: 59 additions & 82 deletions
Large diffs are not rendered by default.
Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
11
import {
22
$,
3-
component$,
3+
QwikIntrinsicElements,
44
Slot,
5-
useVisibleTask$,
5+
component$,
66
useContext,
77
useSignal,
88
useStylesScoped$,
9+
useVisibleTask$
910
} from '@builder.io/qwik';
1011
import { PopoverContext } from './popover-context';
1112
import styles from './popover-trigger.css?inline';
1213

13-
export const PopoverTrigger = component$(() => {
14-
const ref = useSignal<HTMLElement>();
15-
const contextService = useContext(PopoverContext);
16-
useStylesScoped$(styles);
17-
18-
useVisibleTask$(() => {
19-
contextService.setTriggerRef$(ref);
20-
});
14+
export const PopoverTrigger = component$(
15+
(
16+
props: QwikIntrinsicElements['span'] & {
17+
tabIndex?: number;
18+
}
19+
) => {
20+
const ref = useSignal<HTMLElement>();
21+
const contextService = useContext(PopoverContext);
22+
useStylesScoped$(styles);
2123

22-
const mouseOverHandler = $(() => {
23-
contextService.isOpen = true;
24-
});
24+
useVisibleTask$(() => {
25+
contextService.setTriggerRef$(ref);
26+
});
2527

26-
return (
27-
<span
28-
ref={ref}
29-
role="button"
30-
class="popover-trigger"
31-
onMouseOver$={
32-
contextService.triggerEvent === 'mouseOver'
33-
? mouseOverHandler
34-
: undefined
35-
}
36-
>
37-
<Slot />
38-
</span>
39-
);
40-
});
28+
const mouseOverHandler = $(() => {
29+
contextService.isOpen = true;
30+
});
31+
return (
32+
<span
33+
ref={ref}
34+
{...props}
35+
role="button"
36+
class="popover-trigger"
37+
onMouseOver$={
38+
contextService.triggerEvent === 'mouseOver' ? mouseOverHandler : undefined
39+
}
40+
>
41+
<Slot />
42+
</span>
43+
);
44+
}
45+
);

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const PopoverComponent = component$((props: PopoverProps) => {
77
return (
88
<Popover {...props}>
99
<PopoverContent>popover content</PopoverContent>
10-
<PopoverTrigger>trigger text</PopoverTrigger>
10+
<PopoverTrigger {...props}>trigger text</PopoverTrigger>
1111
</Popover>
1212
);
1313
});
@@ -110,4 +110,10 @@ describe('Popover', () => {
110110

111111
assertClosed();
112112
});
113+
114+
it('should set the arial label', () => {
115+
const label = 'hello';
116+
cy.mount(<PopoverComponent aria-label={label} />);
117+
cy.findByRole('button').should('have.attr', 'aria-label', label);
118+
});
113119
});

0 commit comments

Comments
 (0)