Skip to content

Commit 23ce320

Browse files
committed
fix: add tests and improve accessibility
1 parent 3c53980 commit 23ce320

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

.changeset/lazy-lights-invent.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
"@ultraviolet/ui": minor
33
---
44

5-
Refactor components `TagInput` and `TagList` to use vanilla-extract instead of emotion
5+
- Refactor components `TagInput` and `TagList` to use vanilla-extract instead of emotion
6+
- `TagList` : popover should be openable using keyboard keys (space or enter)

packages/ui/src/components/TagList/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ exports[`tagList > renders correctly 1`] = `
3232
<span
3333
class="styles__1f9zr5y5"
3434
data-testid="taglist-open"
35+
tabindex="0"
3536
>
3637
+1
3738
</span>
@@ -92,14 +93,15 @@ exports[`tagList > renders correctly a scrollable popover with non default popov
9293
</div>
9394
</div>
9495
<div
95-
aria-controls="«r1v»"
96-
aria-describedby="«r1v»"
96+
aria-controls="«r27»"
97+
aria-describedby="«r27»"
9798
class="styles__w40vpo9"
9899
tabindex="-1"
99100
>
100101
<span
101102
class="styles__1f9zr5y5"
102103
data-testid="taglist-open"
104+
tabindex="0"
103105
>
104106
+51
105107
</span>
@@ -169,6 +171,7 @@ exports[`tagList > renders correctly and ignore custom threshold as it does not
169171
<span
170172
class="styles__1f9zr5y5"
171173
data-testid="taglist-open"
174+
tabindex="0"
172175
>
173176
+2
174177
</span>
@@ -307,6 +310,7 @@ exports[`tagList > renders correctly with custom threshold and extra tags 1`] =
307310
<span
308311
class="styles__1f9zr5y5"
309312
data-testid="taglist-open"
313+
tabindex="0"
310314
>
311315
+1
312316
</span>
@@ -348,6 +352,7 @@ exports[`tagList > renders correctly with custom threshold and extra tags and ma
348352
<span
349353
class="styles__1f9zr5y5"
350354
data-testid="taglist-open"
355+
tabindex="0"
351356
>
352357
+2
353358
</span>
@@ -449,6 +454,7 @@ exports[`tagList > renders correctly with multiline 1`] = `
449454
<span
450455
class="styles__1f9zr5y5"
451456
data-testid="taglist-open"
457+
tabindex="0"
452458
>
453459
+1
454460
</span>
@@ -498,6 +504,7 @@ exports[`tagList > renders correctly with placement 1`] = `
498504
<span
499505
class="styles__1f9zr5y5"
500506
data-testid="taglist-open"
507+
tabindex="0"
501508
>
502509
+1
503510
</span>

packages/ui/src/components/TagList/__tests__/index.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,36 @@ describe('tagList', () => {
201201
})
202202
})
203203

204+
test('renders correctly when clicking on popover via keyboard event', async () => {
205+
const tags: TagType[] = [
206+
{ icon: 'id', label: 'smooth' },
207+
'code',
208+
{ icon: 'lock', label: 'hello' },
209+
{ icon: 'plus', label: 'world' },
210+
]
211+
212+
mockOffsetWidth(tags)
213+
214+
renderWithTheme(
215+
<TagList popoverTitle="Additional" tags={tags} threshold={1} />,
216+
)
217+
218+
expect(screen.queryByText('Additional')).not.toBeInTheDocument()
219+
220+
const plus = screen.getByTestId('taglist-open')
221+
plus.focus()
222+
await userEvent.keyboard(' ')
223+
224+
expect(screen.getByText('Additional')).toBeInTheDocument()
225+
226+
const closeButton = screen.getByLabelText('close')
227+
await userEvent.click(closeButton)
228+
229+
await waitFor(() => {
230+
expect(screen.queryByText('Additional')).not.toBeInTheDocument()
231+
})
232+
})
233+
204234
test('renders correctly a scrollable popover with non default popoverMaxHeight', async () => {
205235
const tags: TagType[] = [
206236
'very',

packages/ui/src/components/TagList/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ export const TagList = ({
327327
}
328328
}}
329329
ref={popoverTriggerRef}
330+
tabIndex={0}
330331
>
331332
+{hiddenTags.length}
332333
</span>

0 commit comments

Comments
 (0)