@aleph-alpha/ui-library 2.4.2 → 2.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/system/components/UiSelect/UiSelectItem.vue.d.ts +4 -1
- package/dist/system/components/core/select/SelectItem.vue.d.ts +1 -0
- package/dist/system/lib.js +1663 -1640
- package/package.json +4 -1
- package/src/components/UiDrawer/UiDrawer.stories.ts +8 -8
- package/src/components/UiIcon/__tests__/UiIcon.test.ts +10 -0
- package/src/components/UiSelect/UiSelect.stories.ts +98 -0
- package/src/components/UiSelect/UiSelectContent.vue +1 -1
- package/src/components/UiSelect/UiSelectItem.vue +12 -2
- package/src/components/UiSelect/UiSelectTrigger.vue +2 -2
- package/src/components/UiSelect/__tests__/UiSelectContent.test.ts +31 -0
- package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +110 -0
- package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +88 -0
- package/src/components/core/select/SelectItem.vue +6 -2
- package/src/components/core/select/SelectTrigger.vue +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aleph-alpha/ui-library",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/system/lib.js",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"test:storybook": "Builds Storybook and runs axe tests via test-runner",
|
|
40
40
|
"test:all": "Runs all tests (unit + storybook)",
|
|
41
41
|
"storybook": "Starts interactive Storybook development server on port 6006 for local component development",
|
|
42
|
+
"chromatic": "Runs Chromatic visual regression against the Storybook build (requires CHROMATIC_PROJECT_TOKEN)",
|
|
42
43
|
"test:e2e": "Runs end-to-end integration tests with Playwright"
|
|
43
44
|
},
|
|
44
45
|
"homepage": "https://docs.aleph-alpha.com",
|
|
@@ -56,6 +57,7 @@
|
|
|
56
57
|
"@unocss/reset": "66.5.9",
|
|
57
58
|
"@unocss/vite": "^66.5.10",
|
|
58
59
|
"@vitest/browser": "^3.0.0",
|
|
60
|
+
"chromatic": "16.5.0",
|
|
59
61
|
"concurrently": "9.2.1",
|
|
60
62
|
"eslint-plugin-jsdoc": "^61.0.0",
|
|
61
63
|
"eslint-plugin-vuejs-accessibility": "^2.4.1",
|
|
@@ -127,6 +129,7 @@
|
|
|
127
129
|
"test:all": "vitest --run",
|
|
128
130
|
"storybook": "storybook dev -p 6006",
|
|
129
131
|
"build-storybook": "storybook build",
|
|
132
|
+
"chromatic": "npx chromatic --build-script-name=build-storybook --exit-zero-on-changes",
|
|
130
133
|
"test:e2e": "playwright test",
|
|
131
134
|
"publish:local": "yalc publish && yalc push --sig"
|
|
132
135
|
}
|
|
@@ -67,7 +67,7 @@ import {
|
|
|
67
67
|
This is a shadcn-style drawer built on top of reka-ui Dialog primitives.
|
|
68
68
|
</UiDrawerDescription>
|
|
69
69
|
</UiDrawerHeader>
|
|
70
|
-
<div class="p-4 pt-0 body-14-regular"
|
|
70
|
+
<div class="p-4 pt-0 body-14-regular">
|
|
71
71
|
Put any content here.
|
|
72
72
|
</div>
|
|
73
73
|
<UiDrawerFooter>
|
|
@@ -127,7 +127,7 @@ export const Default: Story = {
|
|
|
127
127
|
This is a shadcn-style drawer built on top of reka-ui Dialog primitives.
|
|
128
128
|
</UiDrawerDescription>
|
|
129
129
|
</UiDrawerHeader>
|
|
130
|
-
<div class="p-4 pt-0 body-14-regular"
|
|
130
|
+
<div class="p-4 pt-0 body-14-regular">
|
|
131
131
|
Put any content here.
|
|
132
132
|
</div>
|
|
133
133
|
<UiDrawerFooter>
|
|
@@ -272,7 +272,7 @@ import {
|
|
|
272
272
|
Outside interaction is allowed.
|
|
273
273
|
</UiDrawerDescription>
|
|
274
274
|
</UiDrawerHeader>
|
|
275
|
-
<div class="p-4 pt-0 body-14-regular"
|
|
275
|
+
<div class="p-4 pt-0 body-14-regular">
|
|
276
276
|
Try selecting text outside the drawer.
|
|
277
277
|
</div>
|
|
278
278
|
<UiDrawerFooter>
|
|
@@ -318,7 +318,7 @@ export const NonModal: Story = {
|
|
|
318
318
|
Outside interaction is allowed.
|
|
319
319
|
</UiDrawerDescription>
|
|
320
320
|
</UiDrawerHeader>
|
|
321
|
-
<div class="p-4 pt-0 body-14-regular"
|
|
321
|
+
<div class="p-4 pt-0 body-14-regular">
|
|
322
322
|
Try selecting text outside the drawer.
|
|
323
323
|
</div>
|
|
324
324
|
<UiDrawerFooter>
|
|
@@ -363,7 +363,7 @@ import {
|
|
|
363
363
|
The drawer handle bar is disabled via showHandle.
|
|
364
364
|
</UiDrawerDescription>
|
|
365
365
|
</UiDrawerHeader>
|
|
366
|
-
<div class="p-4 pt-0 body-14-regular"
|
|
366
|
+
<div class="p-4 pt-0 body-14-regular">
|
|
367
367
|
Content without handle.
|
|
368
368
|
</div>
|
|
369
369
|
<UiDrawerFooter>
|
|
@@ -404,7 +404,7 @@ export const WithoutHandle: Story = {
|
|
|
404
404
|
The drawer handle bar is disabled via showHandle.
|
|
405
405
|
</UiDrawerDescription>
|
|
406
406
|
</UiDrawerHeader>
|
|
407
|
-
<div class="p-4 pt-0 body-14-regular"
|
|
407
|
+
<div class="p-4 pt-0 body-14-regular">
|
|
408
408
|
Content without handle.
|
|
409
409
|
</div>
|
|
410
410
|
<UiDrawerFooter>
|
|
@@ -540,7 +540,7 @@ const open = ref(true)
|
|
|
540
540
|
Useful for visual regression testing.
|
|
541
541
|
</UiDrawerDescription>
|
|
542
542
|
</UiDrawerHeader>
|
|
543
|
-
<div class="p-4 pt-0 body-14-regular"
|
|
543
|
+
<div class="p-4 pt-0 body-14-regular">
|
|
544
544
|
This drawer starts open.
|
|
545
545
|
</div>
|
|
546
546
|
<UiDrawerFooter>
|
|
@@ -585,7 +585,7 @@ export const OpenByDefault: Story = {
|
|
|
585
585
|
Useful for visual regression testing.
|
|
586
586
|
</UiDrawerDescription>
|
|
587
587
|
</UiDrawerHeader>
|
|
588
|
-
<div class="p-4 pt-0 body-14-regular"
|
|
588
|
+
<div class="p-4 pt-0 body-14-regular">
|
|
589
589
|
This drawer starts open.
|
|
590
590
|
</div>
|
|
591
591
|
<UiDrawerFooter>
|
|
@@ -42,6 +42,16 @@ describe('UiIcon', () => {
|
|
|
42
42
|
expect(el).toHaveAttribute('height', '32');
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
test('maps named size tokens to pixels', () => {
|
|
46
|
+
const { container } = render(UiIcon, {
|
|
47
|
+
props: { name: 'star', size: 's' },
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const el = container.querySelector('[data-slot="icon"]');
|
|
51
|
+
expect(el).toHaveAttribute('width', '16');
|
|
52
|
+
expect(el).toHaveAttribute('height', '16');
|
|
53
|
+
});
|
|
54
|
+
|
|
45
55
|
test('does not render when icon name is invalid', () => {
|
|
46
56
|
const { container } = render(UiIcon, {
|
|
47
57
|
props: { name: 'non-existent-icon-xyz' },
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
UiSelectGroup,
|
|
11
11
|
UiSelectSeparator,
|
|
12
12
|
} from './index';
|
|
13
|
+
import { UiIcon } from '@/components/UiIcon';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* UiSelect is a trigger-and-dropdown primitive for choosing one option from a list, with grouped options, separators, and labels.
|
|
@@ -264,6 +265,103 @@ export const WithDisabledItems: Story = {
|
|
|
264
265
|
},
|
|
265
266
|
};
|
|
266
267
|
|
|
268
|
+
const withIconsTemplateSource = `<script setup lang="ts">
|
|
269
|
+
import { ref } from 'vue'
|
|
270
|
+
import {
|
|
271
|
+
UiIcon,
|
|
272
|
+
UiSelect,
|
|
273
|
+
UiSelectTrigger,
|
|
274
|
+
UiSelectContent,
|
|
275
|
+
UiSelectItem,
|
|
276
|
+
UiSelectValue,
|
|
277
|
+
} from '@aleph-alpha/ui-library'
|
|
278
|
+
|
|
279
|
+
const value = ref('')
|
|
280
|
+
</script>
|
|
281
|
+
|
|
282
|
+
<template>
|
|
283
|
+
<UiSelect v-model="value">
|
|
284
|
+
<UiSelectTrigger class="w-[220px]">
|
|
285
|
+
<UiSelectValue placeholder="Select chart type" />
|
|
286
|
+
</UiSelectTrigger>
|
|
287
|
+
<UiSelectContent>
|
|
288
|
+
<UiSelectItem value="line">
|
|
289
|
+
<div class="flex items-center gap-3">
|
|
290
|
+
<UiIcon name="chart-line" size="s" />
|
|
291
|
+
<span>Line</span>
|
|
292
|
+
</div>
|
|
293
|
+
</UiSelectItem>
|
|
294
|
+
<UiSelectItem value="bar">
|
|
295
|
+
<div class="flex items-center gap-3">
|
|
296
|
+
<UiIcon name="chart-bar" size="s" />
|
|
297
|
+
<span>Bar</span>
|
|
298
|
+
</div>
|
|
299
|
+
</UiSelectItem>
|
|
300
|
+
<UiSelectItem value="pie">
|
|
301
|
+
<div class="flex items-center gap-3">
|
|
302
|
+
<UiIcon name="chart-pie" size="s" />
|
|
303
|
+
<span>Pie</span>
|
|
304
|
+
</div>
|
|
305
|
+
</UiSelectItem>
|
|
306
|
+
</UiSelectContent>
|
|
307
|
+
</UiSelect>
|
|
308
|
+
</template>`;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Select items can render icons in their default slot. Use this for visual
|
|
312
|
+
* option lists where each choice has a leading symbol.
|
|
313
|
+
*/
|
|
314
|
+
export const WithIcons: Story = {
|
|
315
|
+
render: (args) => ({
|
|
316
|
+
components: {
|
|
317
|
+
UiIcon,
|
|
318
|
+
UiSelect,
|
|
319
|
+
UiSelectTrigger,
|
|
320
|
+
UiSelectContent,
|
|
321
|
+
UiSelectItem,
|
|
322
|
+
UiSelectValue,
|
|
323
|
+
},
|
|
324
|
+
setup() {
|
|
325
|
+
const value = ref('');
|
|
326
|
+
return { args, value };
|
|
327
|
+
},
|
|
328
|
+
template: `
|
|
329
|
+
<UiSelect v-model="value" v-bind="args">
|
|
330
|
+
<UiSelectTrigger class="w-[220px]">
|
|
331
|
+
<UiSelectValue placeholder="Select chart type" />
|
|
332
|
+
</UiSelectTrigger>
|
|
333
|
+
<UiSelectContent>
|
|
334
|
+
<UiSelectItem value="line">
|
|
335
|
+
<div class="flex items-center gap-3">
|
|
336
|
+
<UiIcon name="chart-line" size="s" />
|
|
337
|
+
<span>Line</span>
|
|
338
|
+
</div>
|
|
339
|
+
</UiSelectItem>
|
|
340
|
+
<UiSelectItem value="bar">
|
|
341
|
+
<div class="flex items-center gap-3">
|
|
342
|
+
<UiIcon name="chart-bar" size="s" />
|
|
343
|
+
<span>Bar</span>
|
|
344
|
+
</div>
|
|
345
|
+
</UiSelectItem>
|
|
346
|
+
<UiSelectItem value="pie">
|
|
347
|
+
<div class="flex items-center gap-3">
|
|
348
|
+
<UiIcon name="chart-pie" size="s" />
|
|
349
|
+
<span>Pie</span>
|
|
350
|
+
</div>
|
|
351
|
+
</UiSelectItem>
|
|
352
|
+
</UiSelectContent>
|
|
353
|
+
</UiSelect>
|
|
354
|
+
`,
|
|
355
|
+
}),
|
|
356
|
+
parameters: {
|
|
357
|
+
docs: {
|
|
358
|
+
source: {
|
|
359
|
+
code: withIconsTemplateSource,
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
|
|
267
365
|
const disabledTemplateSource = `<script setup lang="ts">
|
|
268
366
|
import { ref } from 'vue'
|
|
269
367
|
import {
|
|
@@ -41,7 +41,7 @@ const ctx = useUiSelectContext();
|
|
|
41
41
|
:side-offset="props.sideOffset"
|
|
42
42
|
:align="props.align"
|
|
43
43
|
:force-mount="true"
|
|
44
|
-
class="min-w-(--reka-popper-anchor-width) w-(--reka-popper-anchor-width) max-w-(--reka-popper-available-width) p-1 data-[state=closed]:
|
|
44
|
+
class="min-w-(--reka-popper-anchor-width) w-(--reka-popper-anchor-width) max-w-(--reka-popper-available-width) p-1 data-[state=closed]:hidden data-[state=closed]:pointer-events-none"
|
|
45
45
|
@escape-key-down="emit('escapeKeyDown', $event)"
|
|
46
46
|
@pointer-down-outside="emit('pointerDownOutside', $event)"
|
|
47
47
|
>
|
|
@@ -77,6 +77,12 @@ onBeforeUnmount(() => {
|
|
|
77
77
|
:disabled="props.disabled"
|
|
78
78
|
:text-value="props.textValue"
|
|
79
79
|
>
|
|
80
|
+
<template v-if="$slots['right-icon']" #right-icon>
|
|
81
|
+
<slot name="right-icon" />
|
|
82
|
+
</template>
|
|
83
|
+
<template v-if="$slots['indicator-icon']" #indicator-icon>
|
|
84
|
+
<slot name="indicator-icon" />
|
|
85
|
+
</template>
|
|
80
86
|
<slot />
|
|
81
87
|
</ShadcnSelectItem>
|
|
82
88
|
|
|
@@ -85,12 +91,16 @@ onBeforeUnmount(() => {
|
|
|
85
91
|
:value="props.value"
|
|
86
92
|
:disabled="props.disabled"
|
|
87
93
|
:text-value="props.textValue"
|
|
88
|
-
class="hover-layer hover-layer-default focus:text-foreground data-[highlighted]:text-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-
|
|
94
|
+
class="hover-layer hover-layer-default focus:text-foreground data-[highlighted]:text-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-12 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
|
|
89
95
|
>
|
|
90
96
|
<span ref="labelEl" class="flex items-center gap-2">
|
|
91
97
|
<slot />
|
|
92
98
|
</span>
|
|
93
|
-
<span
|
|
99
|
+
<span
|
|
100
|
+
class="!absolute right-2 flex items-center justify-center gap-1"
|
|
101
|
+
data-slot="select-item-end"
|
|
102
|
+
>
|
|
103
|
+
<slot name="right-icon" />
|
|
94
104
|
<ShadcnListboxItemIndicator>
|
|
95
105
|
<slot name="indicator-icon">
|
|
96
106
|
<UiIcon name="check" :size="16" />
|
|
@@ -34,7 +34,7 @@ const isMultiPlaceholder = computed(
|
|
|
34
34
|
// shadcn trigger styles target only SVG icons (`[&_svg]...`) but our icons are spans (`data-slot="icon"`).
|
|
35
35
|
// Add equivalent sizing/behavior + rotate-on-open for the chevron.
|
|
36
36
|
const uiIconTriggerClasses =
|
|
37
|
-
'[&_[data-slot=icon]]:pointer-events-none [&_[data-slot=icon]]:shrink-0 [&_[data-slot=icon]]:
|
|
37
|
+
'[&_[data-slot=icon]]:pointer-events-none [&_[data-slot=icon]]:shrink-0 [&_[data-slot=icon]]:transition-transform [&_[data-slot=icon]]:duration-200 [&[data-state=open]_[data-slot=icon]]:rotate-180';
|
|
38
38
|
|
|
39
39
|
// In multi-select mode, we render a Popover instead of reka-ui's Select, so
|
|
40
40
|
// we have to recreate the SelectTrigger button (incl. the styling that
|
|
@@ -50,7 +50,7 @@ const uiIconTriggerClasses =
|
|
|
50
50
|
// truncate inside the flex row instead of forcing the button wider.
|
|
51
51
|
const multiTriggerClasses = computed(() =>
|
|
52
52
|
cn(
|
|
53
|
-
"border-input data-[placeholder]:text-muted-foreground data-[placeholder]:bg-background-input-default [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive flex max-w-full items-center justify-between gap-2 rounded-md border bg-accent px-3 py-2 text-sm
|
|
53
|
+
"border-input data-[placeholder]:text-muted-foreground data-[placeholder]:bg-background-input-default [&:not([data-placeholder])]:border-border-surface-focus-ring [&_svg:not([class*='text-'])]:text-muted-foreground focus:border-border-surface-focus-ring focus-visible:border-border-surface-focus-ring active:border-border-surface-focus-ring data-[state=open]:border-border-surface-focus-ring focus:ring-ring/50 focus-visible:ring-ring/50 focus:shadow-xs focus-visible:shadow-xs aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive flex max-w-full items-center justify-between gap-2 rounded-md border bg-accent px-3 py-2 text-sm transition-[color,box-shadow] outline-none focus:ring-[3px] focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 *:data-[slot=select-value]:min-w-0 *:data-[slot=select-value]:flex-1 *:data-[slot=select-value]:truncate [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([data-slot=icon]):not([class*='size-'])]:size-4",
|
|
54
54
|
props.size === 'default' ? 'h-9' : 'h-8',
|
|
55
55
|
uiIconTriggerClasses,
|
|
56
56
|
),
|
|
@@ -39,4 +39,35 @@ describe('UiSelectContent', () => {
|
|
|
39
39
|
expect(getByRole('listbox')).toHaveClass('max-h-[200px]');
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
|
+
|
|
43
|
+
test('hides multi-select content while closed without losing selected label', async () => {
|
|
44
|
+
const { container, getByRole } = render({
|
|
45
|
+
components: {
|
|
46
|
+
UiSelect,
|
|
47
|
+
UiSelectTrigger,
|
|
48
|
+
UiSelectContent,
|
|
49
|
+
UiSelectItem,
|
|
50
|
+
UiSelectValue,
|
|
51
|
+
},
|
|
52
|
+
template: `
|
|
53
|
+
<UiSelect :multiple="true" :default-value="['a']">
|
|
54
|
+
<UiSelectTrigger>
|
|
55
|
+
<UiSelectValue placeholder="Select" />
|
|
56
|
+
</UiSelectTrigger>
|
|
57
|
+
<UiSelectContent>
|
|
58
|
+
<UiSelectItem value="a">Option A</UiSelectItem>
|
|
59
|
+
</UiSelectContent>
|
|
60
|
+
</UiSelect>
|
|
61
|
+
`,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
await waitFor(() => {
|
|
65
|
+
expect(getByRole('button')).toHaveTextContent('Option A');
|
|
66
|
+
});
|
|
67
|
+
expect(
|
|
68
|
+
container.ownerDocument.body.querySelector(
|
|
69
|
+
'[data-slot="select-content"]',
|
|
70
|
+
),
|
|
71
|
+
).toHaveClass('data-[state=closed]:hidden');
|
|
72
|
+
});
|
|
42
73
|
});
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
UiSelectItem,
|
|
10
10
|
UiSelectValue,
|
|
11
11
|
} from '../index';
|
|
12
|
+
import { UiIcon } from '../../UiIcon';
|
|
12
13
|
|
|
13
14
|
describe('UiSelectItem', () => {
|
|
14
15
|
test('applies custom class', async () => {
|
|
@@ -72,6 +73,115 @@ describe('UiSelectItem', () => {
|
|
|
72
73
|
});
|
|
73
74
|
});
|
|
74
75
|
|
|
76
|
+
test('renders right icon and keeps indicator on the right in single select', async () => {
|
|
77
|
+
const user = userEvent.setup();
|
|
78
|
+
const { getByRole, getByTestId } = render({
|
|
79
|
+
components: {
|
|
80
|
+
UiSelect,
|
|
81
|
+
UiSelectTrigger,
|
|
82
|
+
UiSelectContent,
|
|
83
|
+
UiSelectItem,
|
|
84
|
+
UiSelectValue,
|
|
85
|
+
},
|
|
86
|
+
template: `
|
|
87
|
+
<UiSelect default-value="a">
|
|
88
|
+
<UiSelectTrigger>
|
|
89
|
+
<UiSelectValue placeholder="Select" />
|
|
90
|
+
</UiSelectTrigger>
|
|
91
|
+
<UiSelectContent>
|
|
92
|
+
<UiSelectItem value="a">
|
|
93
|
+
Option A
|
|
94
|
+
<template #right-icon>
|
|
95
|
+
<span data-testid="right-icon" aria-hidden="true">i</span>
|
|
96
|
+
</template>
|
|
97
|
+
</UiSelectItem>
|
|
98
|
+
</UiSelectContent>
|
|
99
|
+
</UiSelect>
|
|
100
|
+
`,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
await user.click(getByRole('combobox'));
|
|
104
|
+
|
|
105
|
+
const option = getByRole('option', { name: 'Option A' });
|
|
106
|
+
const end = option.querySelector('[data-slot="select-item-end"]');
|
|
107
|
+
|
|
108
|
+
expect(getByTestId('right-icon')).toBeInTheDocument();
|
|
109
|
+
expect(end).toHaveClass('!absolute');
|
|
110
|
+
expect(end).toHaveClass('right-2');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('preserves UiIcon size prop inside select items', async () => {
|
|
114
|
+
const user = userEvent.setup();
|
|
115
|
+
const { getByRole, getByTestId } = render({
|
|
116
|
+
components: {
|
|
117
|
+
UiIcon,
|
|
118
|
+
UiSelect,
|
|
119
|
+
UiSelectTrigger,
|
|
120
|
+
UiSelectContent,
|
|
121
|
+
UiSelectItem,
|
|
122
|
+
UiSelectValue,
|
|
123
|
+
},
|
|
124
|
+
template: `
|
|
125
|
+
<UiSelect>
|
|
126
|
+
<UiSelectTrigger>
|
|
127
|
+
<UiSelectValue placeholder="Select" />
|
|
128
|
+
</UiSelectTrigger>
|
|
129
|
+
<UiSelectContent>
|
|
130
|
+
<UiSelectItem value="line">
|
|
131
|
+
<UiIcon name="chart-line" size="m" data-testid="chart-icon" />
|
|
132
|
+
Line
|
|
133
|
+
</UiSelectItem>
|
|
134
|
+
</UiSelectContent>
|
|
135
|
+
</UiSelect>
|
|
136
|
+
`,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
await user.click(getByRole('combobox'));
|
|
140
|
+
|
|
141
|
+
expect(getByTestId('chart-icon')).toHaveAttribute('width', '20');
|
|
142
|
+
expect(getByTestId('chart-icon')).toHaveAttribute('height', '20');
|
|
143
|
+
expect(getByRole('option', { name: 'Line' })).toHaveClass(
|
|
144
|
+
"[&_svg:not([data-slot=icon]):not([class*='size-'])]:size-4",
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('renders right icon and keeps indicator on the right in multi select', async () => {
|
|
149
|
+
const user = userEvent.setup();
|
|
150
|
+
const { getByRole, getByTestId } = render({
|
|
151
|
+
components: {
|
|
152
|
+
UiSelect,
|
|
153
|
+
UiSelectTrigger,
|
|
154
|
+
UiSelectContent,
|
|
155
|
+
UiSelectItem,
|
|
156
|
+
UiSelectValue,
|
|
157
|
+
},
|
|
158
|
+
template: `
|
|
159
|
+
<UiSelect :multiple="true" :default-value="['a']">
|
|
160
|
+
<UiSelectTrigger>
|
|
161
|
+
<UiSelectValue placeholder="Select" />
|
|
162
|
+
</UiSelectTrigger>
|
|
163
|
+
<UiSelectContent>
|
|
164
|
+
<UiSelectItem value="a">
|
|
165
|
+
Option A
|
|
166
|
+
<template #right-icon>
|
|
167
|
+
<span data-testid="multi-right-icon" aria-hidden="true">i</span>
|
|
168
|
+
</template>
|
|
169
|
+
</UiSelectItem>
|
|
170
|
+
</UiSelectContent>
|
|
171
|
+
</UiSelect>
|
|
172
|
+
`,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
await user.click(getByRole('button', { name: 'a' }));
|
|
176
|
+
|
|
177
|
+
const option = getByRole('option', { name: 'Option A' });
|
|
178
|
+
const end = option.querySelector('[data-slot="select-item-end"]');
|
|
179
|
+
|
|
180
|
+
expect(getByTestId('multi-right-icon')).toBeInTheDocument();
|
|
181
|
+
expect(end).toHaveClass('!absolute');
|
|
182
|
+
expect(end).toHaveClass('right-2');
|
|
183
|
+
});
|
|
184
|
+
|
|
75
185
|
test('cannot select disabled item', async () => {
|
|
76
186
|
const user = userEvent.setup();
|
|
77
187
|
const { getByRole } = render({
|
|
@@ -78,6 +78,60 @@ describe('UiSelectTrigger', () => {
|
|
|
78
78
|
expect(trigger).toHaveAttribute('data-placeholder');
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
+
test('uses focus-ring border for focus and open states without default shadow', () => {
|
|
82
|
+
const { getByRole } = render({
|
|
83
|
+
components: { UiSelect, UiSelectTrigger, UiSelectContent, UiSelectValue },
|
|
84
|
+
template: `
|
|
85
|
+
<UiSelect>
|
|
86
|
+
<UiSelectTrigger>
|
|
87
|
+
<UiSelectValue placeholder="Select" />
|
|
88
|
+
</UiSelectTrigger>
|
|
89
|
+
<UiSelectContent />
|
|
90
|
+
</UiSelect>
|
|
91
|
+
`,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const trigger = getByRole('combobox');
|
|
95
|
+
|
|
96
|
+
expect(trigger).toHaveClass('focus:border-border-surface-focus-ring');
|
|
97
|
+
expect(trigger).toHaveClass(
|
|
98
|
+
'focus-visible:border-border-surface-focus-ring',
|
|
99
|
+
);
|
|
100
|
+
expect(trigger).toHaveClass('active:border-border-surface-focus-ring');
|
|
101
|
+
expect(trigger).toHaveClass(
|
|
102
|
+
'data-[state=open]:border-border-surface-focus-ring',
|
|
103
|
+
);
|
|
104
|
+
expect(trigger).toHaveClass('focus:shadow-xs');
|
|
105
|
+
expect(trigger).not.toHaveClass('shadow-xs');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('uses focus-ring border for multi-select focus and open states without default shadow', () => {
|
|
109
|
+
const { getByRole } = render({
|
|
110
|
+
components: { UiSelect, UiSelectTrigger, UiSelectContent, UiSelectValue },
|
|
111
|
+
template: `
|
|
112
|
+
<UiSelect :multiple="true">
|
|
113
|
+
<UiSelectTrigger>
|
|
114
|
+
<UiSelectValue placeholder="Select" />
|
|
115
|
+
</UiSelectTrigger>
|
|
116
|
+
<UiSelectContent />
|
|
117
|
+
</UiSelect>
|
|
118
|
+
`,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const trigger = getByRole('button');
|
|
122
|
+
|
|
123
|
+
expect(trigger).toHaveClass('focus:border-border-surface-focus-ring');
|
|
124
|
+
expect(trigger).toHaveClass(
|
|
125
|
+
'focus-visible:border-border-surface-focus-ring',
|
|
126
|
+
);
|
|
127
|
+
expect(trigger).toHaveClass('active:border-border-surface-focus-ring');
|
|
128
|
+
expect(trigger).toHaveClass(
|
|
129
|
+
'data-[state=open]:border-border-surface-focus-ring',
|
|
130
|
+
);
|
|
131
|
+
expect(trigger).toHaveClass('focus:shadow-xs');
|
|
132
|
+
expect(trigger).not.toHaveClass('shadow-xs');
|
|
133
|
+
});
|
|
134
|
+
|
|
81
135
|
test('removes data-placeholder when a value is selected', async () => {
|
|
82
136
|
const { getByRole } = render({
|
|
83
137
|
components: {
|
|
@@ -103,6 +157,40 @@ describe('UiSelectTrigger', () => {
|
|
|
103
157
|
const trigger = getByRole('combobox');
|
|
104
158
|
expect(trigger).not.toHaveAttribute('data-placeholder');
|
|
105
159
|
expect(trigger).toHaveTextContent('Option 1');
|
|
160
|
+
expect(trigger).toHaveClass(
|
|
161
|
+
'[&:not([data-placeholder])]:border-border-surface-focus-ring',
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('uses focus-ring border when multi-select has a value', async () => {
|
|
167
|
+
const { getByRole } = render({
|
|
168
|
+
components: {
|
|
169
|
+
UiSelect,
|
|
170
|
+
UiSelectTrigger,
|
|
171
|
+
UiSelectContent,
|
|
172
|
+
UiSelectItem,
|
|
173
|
+
UiSelectValue,
|
|
174
|
+
},
|
|
175
|
+
template: `
|
|
176
|
+
<UiSelect :multiple="true" :default-value="['option1']">
|
|
177
|
+
<UiSelectTrigger>
|
|
178
|
+
<UiSelectValue placeholder="Select" />
|
|
179
|
+
</UiSelectTrigger>
|
|
180
|
+
<UiSelectContent>
|
|
181
|
+
<UiSelectItem value="option1">Option 1</UiSelectItem>
|
|
182
|
+
</UiSelectContent>
|
|
183
|
+
</UiSelect>
|
|
184
|
+
`,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
await waitFor(() => {
|
|
188
|
+
const trigger = getByRole('button');
|
|
189
|
+
expect(trigger).not.toHaveAttribute('data-placeholder');
|
|
190
|
+
expect(trigger).toHaveTextContent('Option 1');
|
|
191
|
+
expect(trigger).toHaveClass(
|
|
192
|
+
'[&:not([data-placeholder])]:border-border-surface-focus-ring',
|
|
193
|
+
);
|
|
106
194
|
});
|
|
107
195
|
});
|
|
108
196
|
});
|
|
@@ -26,12 +26,16 @@ const forwardedProps = useForwardProps(delegatedProps);
|
|
|
26
26
|
v-bind="forwardedProps"
|
|
27
27
|
:class="
|
|
28
28
|
cn(
|
|
29
|
-
'hover-layer hover-layer-default focus:text-foreground [&_svg:not([class*=\'text-\'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-
|
|
29
|
+
'hover-layer hover-layer-default focus:text-foreground [&_svg:not([class*=\'text-\'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-12 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([data-slot=icon]):not([class*=\'size-\'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2',
|
|
30
30
|
props.class,
|
|
31
31
|
)
|
|
32
32
|
"
|
|
33
33
|
>
|
|
34
|
-
<span
|
|
34
|
+
<span
|
|
35
|
+
class="!absolute right-2 order-last flex items-center justify-center gap-1"
|
|
36
|
+
data-slot="select-item-end"
|
|
37
|
+
>
|
|
38
|
+
<slot name="right-icon" />
|
|
35
39
|
<SelectItemIndicator>
|
|
36
40
|
<slot name="indicator-icon">
|
|
37
41
|
<UiIcon name="check" :size="16" />
|
|
@@ -27,7 +27,7 @@ const forwardedProps = useForwardProps(delegatedProps);
|
|
|
27
27
|
v-bind="forwardedProps"
|
|
28
28
|
:class="
|
|
29
29
|
cn(
|
|
30
|
-
'border-input data-[placeholder]:text-muted-foreground data-[placeholder]:bg-background-input-default [&_svg:not([class*=\'text-\'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive flex w-fit items-center justify-between gap-2 rounded-md border bg-accent px-3 py-2 text-sm whitespace-nowrap
|
|
30
|
+
'border-input data-[placeholder]:text-muted-foreground data-[placeholder]:bg-background-input-default [&:not([data-placeholder])]:border-border-surface-focus-ring [&_svg:not([class*=\'text-\'])]:text-muted-foreground focus:border-border-surface-focus-ring focus-visible:border-border-surface-focus-ring active:border-border-surface-focus-ring data-[state=open]:border-border-surface-focus-ring focus:ring-ring/50 focus-visible:ring-ring/50 focus:shadow-xs focus-visible:shadow-xs aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive flex w-fit items-center justify-between gap-2 rounded-md border bg-accent px-3 py-2 text-sm whitespace-nowrap transition-[color,box-shadow] outline-none focus:ring-[3px] focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([data-slot=icon]):not([class*=\'size-\'])]:size-4',
|
|
31
31
|
props.class,
|
|
32
32
|
)
|
|
33
33
|
"
|