@aleph-alpha/ui-library 6.2.1 → 6.3.1
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/UiButtonGroup/index.d.ts +1 -0
- package/dist/system/components/UiDialog/types.d.ts +3 -2
- package/dist/system/components/UiInputGroup/UiInputGroup.vue.d.ts +20 -0
- package/dist/system/components/UiInputGroup/UiInputGroupAddon.vue.d.ts +20 -0
- package/dist/system/components/UiInputGroup/UiInputGroupButton.vue.d.ts +17 -0
- package/dist/system/components/UiInputGroup/UiInputGroupInput.vue.d.ts +11 -0
- package/dist/system/components/UiInputGroup/UiInputGroupTextarea.vue.d.ts +11 -0
- package/dist/system/components/UiInputGroup/index.d.ts +7 -0
- package/dist/system/components/UiInputGroup/types.d.ts +151 -0
- package/dist/system/components/UiLabel/UiLabel.vue.d.ts +3 -1
- package/dist/system/components/UiLabel/types.d.ts +7 -0
- package/dist/system/components/core/input-group/InputGroup.vue.d.ts +25 -0
- package/dist/system/components/core/input-group/InputGroupAddon.vue.d.ts +25 -0
- package/dist/system/components/core/input-group/InputGroupButton.vue.d.ts +28 -0
- package/dist/system/components/core/input-group/InputGroupInput.vue.d.ts +12 -0
- package/dist/system/components/core/input-group/InputGroupText.vue.d.ts +21 -0
- package/dist/system/components/core/input-group/InputGroupTextarea.vue.d.ts +12 -0
- package/dist/system/components/core/input-group/index.d.ts +18 -0
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/lib.js +14622 -14279
- package/package.json +2 -2
- package/src/components/UiButtonGroup/index.ts +4 -0
- package/src/components/UiDialog/UiDialog.stories.ts +151 -54
- package/src/components/UiDialog/UiDialogContent.vue +23 -32
- package/src/components/UiDialog/types.ts +3 -2
- package/src/components/UiField/UiField.stories.ts +329 -52
- package/src/components/UiField/UiFieldLabelInfo.vue +1 -1
- package/src/components/UiInput/UiInput.stories.ts +3 -1
- package/src/components/UiInput/UiInput.vue +26 -5
- package/src/components/UiInputGroup/UiInputGroup.stories.ts +2083 -0
- package/src/components/UiInputGroup/UiInputGroup.vue +18 -0
- package/src/components/UiInputGroup/UiInputGroupAddon.vue +18 -0
- package/src/components/UiInputGroup/UiInputGroupButton.vue +30 -0
- package/src/components/UiInputGroup/UiInputGroupInput.vue +16 -0
- package/src/components/UiInputGroup/UiInputGroupTextarea.vue +16 -0
- package/src/components/UiInputGroup/__tests__/UiInputGroup.test.ts +195 -0
- package/src/components/UiInputGroup/index.ts +10 -0
- package/src/components/UiInputGroup/types.ts +171 -0
- package/src/components/UiLabel/UiLabel.vue +7 -2
- package/src/components/UiLabel/types.ts +8 -0
- package/src/components/core/button/index.ts +23 -13
- package/src/components/core/button-group/ButtonGroupText.vue +4 -0
- package/src/components/core/button-group/index.ts +6 -2
- package/src/components/core/field/FieldError.vue +1 -1
- package/src/components/core/field/FieldLabel.vue +1 -1
- package/src/components/core/field/index.ts +7 -1
- package/src/components/core/input/Input.vue +4 -1
- package/src/components/core/input-group/InputGroup.vue +27 -0
- package/src/components/core/input-group/InputGroupAddon.vue +53 -0
- package/src/components/core/input-group/InputGroupButton.vue +35 -0
- package/src/components/core/input-group/InputGroupInput.vue +65 -0
- package/src/components/core/input-group/InputGroupText.vue +26 -0
- package/src/components/core/input-group/InputGroupTextarea.vue +62 -0
- package/src/components/core/input-group/index.ts +103 -0
- package/src/components/core/label/Label.vue +1 -1
- package/src/components/index.ts +1 -0
- package/src/theme/Typography.stories.ts +144 -6
- package/src/theme/__tests__/typography.test.ts +136 -0
|
@@ -16,6 +16,12 @@ import { UiCheckbox } from '../UiCheckbox';
|
|
|
16
16
|
import { UiChip } from '../UiChip';
|
|
17
17
|
import { UiIcon } from '../UiIcon';
|
|
18
18
|
import { UiInput } from '../UiInput';
|
|
19
|
+
import {
|
|
20
|
+
UiInputGroup,
|
|
21
|
+
UiInputGroupAddon,
|
|
22
|
+
UiInputGroupButton,
|
|
23
|
+
UiInputGroupInput,
|
|
24
|
+
} from '../UiInputGroup';
|
|
19
25
|
import { UiKbd } from '../UiKbd';
|
|
20
26
|
import { UiRadioGroup, UiRadioGroupItem } from '../UiRadioGroup';
|
|
21
27
|
import {
|
|
@@ -1588,45 +1594,156 @@ const validationAndErrorsTemplateSource = `<script setup lang="ts">
|
|
|
1588
1594
|
import { ref } from 'vue'
|
|
1589
1595
|
import {
|
|
1590
1596
|
UiField,
|
|
1591
|
-
UiFieldLabel,
|
|
1592
1597
|
UiFieldError,
|
|
1598
|
+
UiFieldLabel,
|
|
1599
|
+
UiIcon,
|
|
1593
1600
|
UiInput,
|
|
1601
|
+
UiInputGroup,
|
|
1602
|
+
UiInputGroupAddon,
|
|
1603
|
+
UiInputGroupButton,
|
|
1604
|
+
UiInputGroupInput,
|
|
1594
1605
|
} from '@aleph-alpha/ui-library'
|
|
1595
1606
|
|
|
1596
1607
|
const email = ref('not-an-email')
|
|
1608
|
+
const username = ref('john doe')
|
|
1597
1609
|
</script>
|
|
1598
1610
|
|
|
1599
1611
|
<template>
|
|
1600
|
-
<
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1612
|
+
<div class="flex w-full max-w-sm flex-col gap-6">
|
|
1613
|
+
<!-- data-invalid="true" on the field cascades the error color top-down:
|
|
1614
|
+
label, control border, and text turn error-colored via CSS;
|
|
1615
|
+
the placeholder keeps its muted color. The value must be the string
|
|
1616
|
+
"true" (a bare attribute renders "" and matches nothing). aria-invalid
|
|
1617
|
+
on the control conveys the state to assistive technology. -->
|
|
1618
|
+
<UiField data-invalid="true">
|
|
1619
|
+
<UiFieldLabel for="email-invalid">Email</UiFieldLabel>
|
|
1620
|
+
<UiInput id="email-invalid" v-model="email" name="email" type="email" aria-invalid="true" />
|
|
1621
|
+
<UiFieldError>Enter a valid email address.</UiFieldError>
|
|
1622
|
+
</UiField>
|
|
1623
|
+
|
|
1624
|
+
<!-- Inside an input group the cascade also covers addons and buttons. -->
|
|
1625
|
+
<UiField data-invalid="true">
|
|
1626
|
+
<UiFieldLabel for="username-invalid">Username</UiFieldLabel>
|
|
1627
|
+
<UiInputGroup>
|
|
1628
|
+
<UiInputGroupInput id="username-invalid" v-model="username" placeholder="Username" aria-invalid="true" />
|
|
1629
|
+
<UiInputGroupAddon align="inline-end">
|
|
1630
|
+
<UiInputGroupButton size="icon-xs" aria-label="Clear username" @click="username = ''">
|
|
1631
|
+
<UiIcon name="circle-x" :size="16" />
|
|
1632
|
+
</UiInputGroupButton>
|
|
1633
|
+
</UiInputGroupAddon>
|
|
1634
|
+
</UiInputGroup>
|
|
1635
|
+
<UiFieldError>Username must not contain spaces.</UiFieldError>
|
|
1636
|
+
</UiField>
|
|
1637
|
+
</div>
|
|
1605
1638
|
</template>`;
|
|
1606
1639
|
|
|
1607
1640
|
/**
|
|
1608
|
-
* Validation styling + a11y: apply `data-invalid` to the field and `aria-invalid` to the control.
|
|
1641
|
+
* Validation styling + a11y: apply `data-invalid="true"` to the field and `aria-invalid` to the control.
|
|
1642
|
+
* `data-invalid` cascades the error color top-down through CSS — the label, the control border,
|
|
1643
|
+
* the text inside the control, and any input-group addons/buttons all turn error-colored;
|
|
1644
|
+
* only the placeholder keeps its muted color.
|
|
1609
1645
|
* Mirrors the “Validation and Errors” section from shadcn-vue field docs.
|
|
1610
1646
|
*/
|
|
1611
1647
|
export const ValidationAndErrors: Story = {
|
|
1612
1648
|
render: () => ({
|
|
1613
|
-
components: {
|
|
1649
|
+
components: {
|
|
1650
|
+
UiField,
|
|
1651
|
+
UiFieldError,
|
|
1652
|
+
UiFieldLabel,
|
|
1653
|
+
UiIcon,
|
|
1654
|
+
UiInput,
|
|
1655
|
+
UiInputGroup,
|
|
1656
|
+
UiInputGroupAddon,
|
|
1657
|
+
UiInputGroupButton,
|
|
1658
|
+
UiInputGroupInput,
|
|
1659
|
+
},
|
|
1614
1660
|
setup() {
|
|
1615
1661
|
const email = ref('not-an-email');
|
|
1616
|
-
|
|
1662
|
+
const username = ref('john doe');
|
|
1663
|
+
return { email, username };
|
|
1617
1664
|
},
|
|
1618
1665
|
template: `
|
|
1619
|
-
<
|
|
1620
|
-
<
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1666
|
+
<div class="flex w-full max-w-sm flex-col gap-6">
|
|
1667
|
+
<UiField data-invalid="true">
|
|
1668
|
+
<UiFieldLabel for="email-invalid">Email</UiFieldLabel>
|
|
1669
|
+
<UiInput id="email-invalid" v-model="email" name="email" type="email" aria-invalid="true" />
|
|
1670
|
+
<UiFieldError>Enter a valid email address.</UiFieldError>
|
|
1671
|
+
</UiField>
|
|
1672
|
+
|
|
1673
|
+
<UiField data-invalid="true">
|
|
1674
|
+
<UiFieldLabel for="username-invalid">Username</UiFieldLabel>
|
|
1675
|
+
<UiInputGroup>
|
|
1676
|
+
<UiInputGroupInput id="username-invalid" v-model="username" placeholder="Username" aria-invalid="true" />
|
|
1677
|
+
<UiInputGroupAddon align="inline-end">
|
|
1678
|
+
<UiInputGroupButton size="icon-xs" aria-label="Clear username" @click="username = ''">
|
|
1679
|
+
<UiIcon name="circle-x" :size="16" />
|
|
1680
|
+
</UiInputGroupButton>
|
|
1681
|
+
</UiInputGroupAddon>
|
|
1682
|
+
</UiInputGroup>
|
|
1683
|
+
<UiFieldError>Username must not contain spaces.</UiFieldError>
|
|
1684
|
+
</UiField>
|
|
1685
|
+
</div>
|
|
1624
1686
|
`,
|
|
1625
1687
|
}),
|
|
1626
1688
|
parameters: {
|
|
1627
1689
|
controls: { disable: true },
|
|
1628
1690
|
docs: { source: { code: validationAndErrorsTemplateSource } },
|
|
1629
1691
|
},
|
|
1692
|
+
play: async ({ canvasElement, step }) => {
|
|
1693
|
+
// Scenario: the field-level data-invalid switch drives every error visual
|
|
1694
|
+
// through CSS, and the same color resolves on the label, the input group
|
|
1695
|
+
// boundary, and the addon button.
|
|
1696
|
+
const canvas = within(canvasElement);
|
|
1697
|
+
|
|
1698
|
+
await step(
|
|
1699
|
+
'screen-reader: both invalid controls expose aria-invalid (WCAG 4.1.2)',
|
|
1700
|
+
async () => {
|
|
1701
|
+
const email = canvas.getByRole('textbox', { name: 'Email' });
|
|
1702
|
+
await expect(email).toHaveAttribute('aria-invalid', 'true');
|
|
1703
|
+
const username = canvas.getByRole('textbox', { name: 'Username' });
|
|
1704
|
+
await expect(username).toHaveAttribute('aria-invalid', 'true');
|
|
1705
|
+
},
|
|
1706
|
+
);
|
|
1707
|
+
|
|
1708
|
+
await step(
|
|
1709
|
+
'interaction: label, input text, and clear button share the cascaded error color',
|
|
1710
|
+
async () => {
|
|
1711
|
+
const username = canvas.getByRole('textbox', {
|
|
1712
|
+
name: 'Username',
|
|
1713
|
+
});
|
|
1714
|
+
const label = canvasElement.querySelector<HTMLElement>(
|
|
1715
|
+
'label[for="username-invalid"]',
|
|
1716
|
+
);
|
|
1717
|
+
const clear = canvas.getByRole('button', { name: 'Clear username' });
|
|
1718
|
+
await expect(label).not.toBeNull();
|
|
1719
|
+
if (!label) return; // unreachable — the assertion above already threw
|
|
1720
|
+
// Resolve the border/input/error token through a probe. It is authored
|
|
1721
|
+
// in the same `color-mix(...)` form the generated `text-*` utilities
|
|
1722
|
+
// use, so the computed values serialize identically and the comparison
|
|
1723
|
+
// cannot pass with the cascade inactive (all elements sharing an
|
|
1724
|
+
// unrelated fallback color).
|
|
1725
|
+
const probe = document.createElement('span');
|
|
1726
|
+
probe.style.color =
|
|
1727
|
+
'color-mix(in srgb, oklch(var(--border-input-error)) 100%, transparent)';
|
|
1728
|
+
canvasElement.appendChild(probe);
|
|
1729
|
+
const errorColor = getComputedStyle(probe).color;
|
|
1730
|
+
probe.remove();
|
|
1731
|
+
await expect(getComputedStyle(label).color).toBe(errorColor);
|
|
1732
|
+
await expect(getComputedStyle(username).color).toBe(errorColor);
|
|
1733
|
+
await expect(getComputedStyle(clear).color).toBe(errorColor);
|
|
1734
|
+
},
|
|
1735
|
+
);
|
|
1736
|
+
|
|
1737
|
+
await step('interaction: the clear icon renders at 16x16', async () => {
|
|
1738
|
+
const clear = canvas.getByRole('button', { name: 'Clear username' });
|
|
1739
|
+
const icon = clear.querySelector('svg');
|
|
1740
|
+
await expect(icon).not.toBeNull();
|
|
1741
|
+
if (!icon) return; // unreachable — the assertion above already threw
|
|
1742
|
+
const { width, height } = icon.getBoundingClientRect();
|
|
1743
|
+
await expect(width).toBe(16);
|
|
1744
|
+
await expect(height).toBe(16);
|
|
1745
|
+
});
|
|
1746
|
+
},
|
|
1630
1747
|
};
|
|
1631
1748
|
|
|
1632
1749
|
const checkboxGroupTemplateSource = `<script setup lang="ts">
|
|
@@ -2151,9 +2268,94 @@ export const ProfileSettingsForm: Story = {
|
|
|
2151
2268
|
},
|
|
2152
2269
|
};
|
|
2153
2270
|
|
|
2271
|
+
const personalInformationFormTemplateSource = `<script setup lang="ts">
|
|
2272
|
+
import { ref } from 'vue'
|
|
2273
|
+
import {
|
|
2274
|
+
UiButton,
|
|
2275
|
+
UiCheckbox,
|
|
2276
|
+
UiField,
|
|
2277
|
+
UiFieldContent,
|
|
2278
|
+
UiFieldDescription,
|
|
2279
|
+
UiFieldGroup,
|
|
2280
|
+
UiFieldLabel,
|
|
2281
|
+
UiFieldLegend,
|
|
2282
|
+
UiFieldSet,
|
|
2283
|
+
UiIcon,
|
|
2284
|
+
UiInput,
|
|
2285
|
+
UiInputGroup,
|
|
2286
|
+
UiInputGroupAddon,
|
|
2287
|
+
UiInputGroupButton,
|
|
2288
|
+
UiInputGroupInput,
|
|
2289
|
+
} from '@aleph-alpha/ui-library'
|
|
2290
|
+
|
|
2291
|
+
const firstName = ref('')
|
|
2292
|
+
const lastName = ref('')
|
|
2293
|
+
const agreeTerms = ref(false)
|
|
2294
|
+
</script>
|
|
2295
|
+
|
|
2296
|
+
<template>
|
|
2297
|
+
<div class="w-full max-w-sm rounded-xl border border-border-surface-default bg-background-surface-secondary p-6">
|
|
2298
|
+
<UiFieldGroup>
|
|
2299
|
+
<UiFieldSet>
|
|
2300
|
+
<UiFieldLegend>Personal Information</UiFieldLegend>
|
|
2301
|
+
<UiFieldDescription>Your basic contact information.</UiFieldDescription>
|
|
2302
|
+
|
|
2303
|
+
<UiFieldGroup>
|
|
2304
|
+
<UiField data-invalid="true">
|
|
2305
|
+
<UiFieldLabel for="pi-first" tooltip="As it appears on official documents.">First Name</UiFieldLabel>
|
|
2306
|
+
<UiFieldContent>
|
|
2307
|
+
<UiInputGroup>
|
|
2308
|
+
<UiInputGroupInput id="pi-first" v-model="firstName" placeholder="John" aria-invalid="true" />
|
|
2309
|
+
<UiInputGroupAddon align="inline-end">
|
|
2310
|
+
<UiInputGroupButton size="icon-xs" aria-label="Clear first name" @click="firstName = ''">
|
|
2311
|
+
<UiIcon name="circle-x" :size="16" />
|
|
2312
|
+
</UiInputGroupButton>
|
|
2313
|
+
</UiInputGroupAddon>
|
|
2314
|
+
</UiInputGroup>
|
|
2315
|
+
</UiFieldContent>
|
|
2316
|
+
</UiField>
|
|
2317
|
+
|
|
2318
|
+
<UiField data-invalid="true">
|
|
2319
|
+
<UiFieldLabel for="pi-last" tooltip="As it appears on official documents.">Last Name</UiFieldLabel>
|
|
2320
|
+
<UiFieldContent>
|
|
2321
|
+
<UiInputGroup>
|
|
2322
|
+
<UiInputGroupInput id="pi-last" v-model="lastName" placeholder="Doe" aria-invalid="true" />
|
|
2323
|
+
<UiInputGroupAddon align="inline-end">
|
|
2324
|
+
<UiInputGroupButton size="icon-xs" aria-label="Clear last name" @click="lastName = ''">
|
|
2325
|
+
<UiIcon name="circle-x" :size="16" />
|
|
2326
|
+
</UiInputGroupButton>
|
|
2327
|
+
</UiInputGroupAddon>
|
|
2328
|
+
</UiInputGroup>
|
|
2329
|
+
</UiFieldContent>
|
|
2330
|
+
</UiField>
|
|
2331
|
+
|
|
2332
|
+
<UiField data-invalid="true">
|
|
2333
|
+
<UiFieldLabel for="pi-resume" tooltip="PDF or DOCX, max 5 MB.">Upload Resume</UiFieldLabel>
|
|
2334
|
+
<UiInput id="pi-resume" name="resume" type="file" accept=".pdf,.docx" upload-button-label="Choose file" aria-invalid="true" />
|
|
2335
|
+
</UiField>
|
|
2336
|
+
</UiFieldGroup>
|
|
2337
|
+
</UiFieldSet>
|
|
2338
|
+
|
|
2339
|
+
<UiField orientation="responsive" data-invalid="true">
|
|
2340
|
+
<UiCheckbox id="pi-terms" v-model="agreeTerms" name="terms" aria-invalid="true" />
|
|
2341
|
+
<UiFieldContent>
|
|
2342
|
+
<UiFieldLabel for="pi-terms" class="font-normal">I agree to the terms and conditions</UiFieldLabel>
|
|
2343
|
+
</UiFieldContent>
|
|
2344
|
+
</UiField>
|
|
2345
|
+
|
|
2346
|
+
<UiField orientation="horizontal" class="justify-end">
|
|
2347
|
+
<UiButton variant="outline">Cancel</UiButton>
|
|
2348
|
+
<UiButton disabled>Submit</UiButton>
|
|
2349
|
+
</UiField>
|
|
2350
|
+
</UiFieldGroup>
|
|
2351
|
+
</div>
|
|
2352
|
+
</template>`;
|
|
2353
|
+
|
|
2154
2354
|
/**
|
|
2155
|
-
* Personal information form
|
|
2156
|
-
*
|
|
2355
|
+
* Personal information form in an invalid state, composing `UiField` with
|
|
2356
|
+
* `UiInputGroup` (error border via `border/input/error`, inline-end clear
|
|
2357
|
+
* buttons) and `UiInput type="file"`. `data-invalid` on the field colors the
|
|
2358
|
+
* label; `aria-invalid` on the control colors the input boundary.
|
|
2157
2359
|
*/
|
|
2158
2360
|
export const PersonalInformationForm: Story = {
|
|
2159
2361
|
render: () => ({
|
|
@@ -2167,58 +2369,133 @@ export const PersonalInformationForm: Story = {
|
|
|
2167
2369
|
UiFieldLabel,
|
|
2168
2370
|
UiFieldLegend,
|
|
2169
2371
|
UiFieldSet,
|
|
2372
|
+
UiIcon,
|
|
2170
2373
|
UiInput,
|
|
2374
|
+
UiInputGroup,
|
|
2375
|
+
UiInputGroupAddon,
|
|
2376
|
+
UiInputGroupButton,
|
|
2377
|
+
UiInputGroupInput,
|
|
2171
2378
|
},
|
|
2172
2379
|
setup() {
|
|
2173
|
-
const
|
|
2174
|
-
const
|
|
2380
|
+
const firstName = ref('');
|
|
2381
|
+
const lastName = ref('');
|
|
2175
2382
|
const agreeTerms = ref(false);
|
|
2176
|
-
return {
|
|
2383
|
+
return { firstName, lastName, agreeTerms };
|
|
2177
2384
|
},
|
|
2178
2385
|
template: `
|
|
2179
|
-
<div class="w-full max-w-sm">
|
|
2180
|
-
<
|
|
2181
|
-
<
|
|
2182
|
-
<
|
|
2183
|
-
|
|
2184
|
-
<UiFieldDescription>Your basic contact information.</UiFieldDescription>
|
|
2386
|
+
<div class="w-full max-w-sm rounded-xl border border-border-surface-default bg-background-surface-secondary p-6">
|
|
2387
|
+
<UiFieldGroup>
|
|
2388
|
+
<UiFieldSet>
|
|
2389
|
+
<UiFieldLegend>Personal Information</UiFieldLegend>
|
|
2390
|
+
<UiFieldDescription>Your basic contact information.</UiFieldDescription>
|
|
2185
2391
|
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2392
|
+
<UiFieldGroup>
|
|
2393
|
+
<UiField data-invalid="true">
|
|
2394
|
+
<UiFieldLabel for="pi-first" tooltip="As it appears on official documents.">First Name</UiFieldLabel>
|
|
2395
|
+
<UiFieldContent>
|
|
2396
|
+
<UiInputGroup>
|
|
2397
|
+
<UiInputGroupInput id="pi-first" v-model="firstName" placeholder="John" aria-invalid="true" />
|
|
2398
|
+
<UiInputGroupAddon align="inline-end">
|
|
2399
|
+
<UiInputGroupButton size="icon-xs" aria-label="Clear first name" @click="firstName = ''">
|
|
2400
|
+
<UiIcon name="circle-x" :size="16" />
|
|
2401
|
+
</UiInputGroupButton>
|
|
2402
|
+
</UiInputGroupAddon>
|
|
2403
|
+
</UiInputGroup>
|
|
2404
|
+
</UiFieldContent>
|
|
2405
|
+
</UiField>
|
|
2191
2406
|
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2407
|
+
<UiField data-invalid="true">
|
|
2408
|
+
<UiFieldLabel for="pi-last" tooltip="As it appears on official documents.">Last Name</UiFieldLabel>
|
|
2409
|
+
<UiFieldContent>
|
|
2410
|
+
<UiInputGroup>
|
|
2411
|
+
<UiInputGroupInput id="pi-last" v-model="lastName" placeholder="Doe" aria-invalid="true" />
|
|
2412
|
+
<UiInputGroupAddon align="inline-end">
|
|
2413
|
+
<UiInputGroupButton size="icon-xs" aria-label="Clear last name" @click="lastName = ''">
|
|
2414
|
+
<UiIcon name="circle-x" :size="16" />
|
|
2415
|
+
</UiInputGroupButton>
|
|
2416
|
+
</UiInputGroupAddon>
|
|
2417
|
+
</UiInputGroup>
|
|
2418
|
+
</UiFieldContent>
|
|
2419
|
+
</UiField>
|
|
2196
2420
|
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2421
|
+
<UiField data-invalid="true">
|
|
2422
|
+
<UiFieldLabel for="pi-resume" tooltip="PDF or DOCX, max 5 MB.">Upload Resume</UiFieldLabel>
|
|
2423
|
+
<UiInput id="pi-resume" name="resume" type="file" accept=".pdf,.docx" upload-button-label="Choose file" aria-invalid="true" />
|
|
2424
|
+
</UiField>
|
|
2425
|
+
</UiFieldGroup>
|
|
2426
|
+
</UiFieldSet>
|
|
2203
2427
|
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2428
|
+
<UiField orientation="responsive" data-invalid="true">
|
|
2429
|
+
<UiCheckbox id="pi-terms" v-model="agreeTerms" name="terms" aria-invalid="true" />
|
|
2430
|
+
<UiFieldContent>
|
|
2431
|
+
<UiFieldLabel for="pi-terms" class="font-normal">I agree to the terms and conditions</UiFieldLabel>
|
|
2432
|
+
</UiFieldContent>
|
|
2433
|
+
</UiField>
|
|
2210
2434
|
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
</form>
|
|
2435
|
+
<UiField orientation="horizontal" class="justify-end">
|
|
2436
|
+
<UiButton variant="outline">Cancel</UiButton>
|
|
2437
|
+
<UiButton disabled>Submit</UiButton>
|
|
2438
|
+
</UiField>
|
|
2439
|
+
</UiFieldGroup>
|
|
2217
2440
|
</div>
|
|
2218
2441
|
`,
|
|
2219
2442
|
}),
|
|
2220
2443
|
parameters: {
|
|
2221
2444
|
controls: { disable: true },
|
|
2445
|
+
docs: { source: { code: personalInformationFormTemplateSource } },
|
|
2446
|
+
},
|
|
2447
|
+
play: async ({ canvasElement, step }) => {
|
|
2448
|
+
// Scenario: the invalid state is conveyed both visually (error border on
|
|
2449
|
+
// the group, error-colored labels) and programmatically (aria-invalid),
|
|
2450
|
+
// and the inline clear buttons stay operable.
|
|
2451
|
+
const canvas = within(canvasElement);
|
|
2452
|
+
|
|
2453
|
+
await step(
|
|
2454
|
+
'screen-reader: invalid controls expose aria-invalid (WCAG 4.1.2)',
|
|
2455
|
+
async () => {
|
|
2456
|
+
const firstName = canvas.getByRole('textbox', { name: /First Name/ });
|
|
2457
|
+
await expect(firstName).toHaveAttribute('aria-invalid', 'true');
|
|
2458
|
+
const checkbox = canvas.getByRole('checkbox', {
|
|
2459
|
+
name: 'I agree to the terms and conditions',
|
|
2460
|
+
});
|
|
2461
|
+
await expect(checkbox).toHaveAttribute('aria-invalid', 'true');
|
|
2462
|
+
},
|
|
2463
|
+
);
|
|
2464
|
+
|
|
2465
|
+
await step(
|
|
2466
|
+
'interaction: the inline clear button empties the field',
|
|
2467
|
+
async () => {
|
|
2468
|
+
const firstName = canvas.getByRole('textbox', {
|
|
2469
|
+
name: /First Name/,
|
|
2470
|
+
}) as HTMLInputElement;
|
|
2471
|
+
await userEvent.type(firstName, 'Johanna');
|
|
2472
|
+
await expect(firstName.value).toBe('Johanna');
|
|
2473
|
+
const clear = canvas.getByRole('button', {
|
|
2474
|
+
name: 'Clear first name',
|
|
2475
|
+
});
|
|
2476
|
+
await userEvent.click(clear);
|
|
2477
|
+
await waitFor(() => expect(firstName.value).toBe(''));
|
|
2478
|
+
},
|
|
2479
|
+
);
|
|
2480
|
+
|
|
2481
|
+
await step(
|
|
2482
|
+
'interaction: the label info icon shares the cascaded error color',
|
|
2483
|
+
async () => {
|
|
2484
|
+
const label = canvasElement.querySelector<HTMLElement>(
|
|
2485
|
+
'label[for="pi-first"]',
|
|
2486
|
+
);
|
|
2487
|
+
const info = canvas.getAllByRole('button', {
|
|
2488
|
+
name: 'As it appears on official documents.',
|
|
2489
|
+
})[0];
|
|
2490
|
+
const icon = info?.querySelector('svg');
|
|
2491
|
+
await expect(label).not.toBeNull();
|
|
2492
|
+
await expect(icon).not.toBeNull();
|
|
2493
|
+
if (!label || !icon) return; // unreachable — the assertions above already threw
|
|
2494
|
+
await expect(getComputedStyle(icon).color).toBe(
|
|
2495
|
+
getComputedStyle(label).color,
|
|
2496
|
+
);
|
|
2497
|
+
},
|
|
2498
|
+
);
|
|
2222
2499
|
},
|
|
2223
2500
|
};
|
|
2224
2501
|
|
|
@@ -19,7 +19,7 @@ const props = withDefaults(defineProps<UiFieldLabelInfoProps>(), {
|
|
|
19
19
|
<UiIcon
|
|
20
20
|
:name="props.icon"
|
|
21
21
|
:size="14"
|
|
22
|
-
class="text-content-on-surface-muted"
|
|
22
|
+
class="text-content-on-surface-muted group-data-[invalid=true]/field:text-border-input-error"
|
|
23
23
|
/>
|
|
24
24
|
</UiButton>
|
|
25
25
|
</UiTooltip>
|
|
@@ -336,7 +336,9 @@ export const FileUpload: Story = {
|
|
|
336
336
|
await step(
|
|
337
337
|
'screen-reader: the upload control exposes an accessible name (WCAG 4.1.2)',
|
|
338
338
|
async () => {
|
|
339
|
-
|
|
339
|
+
// Both the external <label for> and the internal upload-button label
|
|
340
|
+
// are associated with the hidden file input and contribute to it.
|
|
341
|
+
await expect(fileInput).toHaveAccessibleName('Attachment Upload');
|
|
340
342
|
},
|
|
341
343
|
);
|
|
342
344
|
|
|
@@ -30,6 +30,25 @@ const model = defineModel<string>();
|
|
|
30
30
|
const attrs = useAttrs();
|
|
31
31
|
const isFile = computed(() => props.type === 'file');
|
|
32
32
|
|
|
33
|
+
// In file mode the consumer-provided `id` must land on the hidden file input
|
|
34
|
+
// (not the wrapper div) so an external `<label for="...">` opens the picker.
|
|
35
|
+
const fileInputId = computed(
|
|
36
|
+
() => (attrs.id as string | undefined) ?? `${props.name}-file-input`,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const fileWrapperAttrs = computed(() => {
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- rest-destructuring to drop `id`
|
|
41
|
+
const { id, ...rest } = attrs;
|
|
42
|
+
return rest;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// aria-invalid is forwarded through attrs onto the file-mode wrapper; mirror
|
|
46
|
+
// it on the placeholder text so "No file chosen" adopts the error color.
|
|
47
|
+
const isInvalid = computed(() => {
|
|
48
|
+
const value = attrs['aria-invalid'];
|
|
49
|
+
return value === true || value === 'true' || value === '';
|
|
50
|
+
});
|
|
51
|
+
|
|
33
52
|
const selectedFiles = ref<File[]>([]);
|
|
34
53
|
|
|
35
54
|
const filePlaceholder = computed(() => props.placeholder ?? 'No file chosen');
|
|
@@ -41,8 +60,6 @@ const fileDisplayValue = computed(() => {
|
|
|
41
60
|
return `${selectedFiles.value.length} files selected`;
|
|
42
61
|
});
|
|
43
62
|
|
|
44
|
-
const fileInputId = computed(() => `${props.name}-file-input`);
|
|
45
|
-
|
|
46
63
|
function handleFilesChange(e: Event) {
|
|
47
64
|
const target = e.target as HTMLInputElement;
|
|
48
65
|
const files = Array.from(target.files ?? []);
|
|
@@ -60,8 +77,8 @@ function handleFilesChange(e: Event) {
|
|
|
60
77
|
-->
|
|
61
78
|
<div
|
|
62
79
|
v-if="isFile"
|
|
63
|
-
v-bind="
|
|
64
|
-
class="flex h-9 w-full min-w-0 items-center gap-2 rounded-md border border-input bg-background-input-default px-1 transition-[color] outline-none ui-focus-ring-within aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-
|
|
80
|
+
v-bind="fileWrapperAttrs"
|
|
81
|
+
class="flex h-9 w-full min-w-0 items-center gap-2 rounded-md border border-input bg-background-input-default px-1 transition-[color] outline-none ui-focus-ring-within aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-border-input-error group-data-[invalid=true]/field:border-border-input-error"
|
|
65
82
|
:class="{
|
|
66
83
|
'pointer-events-none cursor-not-allowed opacity-50': props.disabled,
|
|
67
84
|
}"
|
|
@@ -85,7 +102,11 @@ function handleFilesChange(e: Event) {
|
|
|
85
102
|
</UiButton>
|
|
86
103
|
<span
|
|
87
104
|
class="placeholder:text-content-on-surface-muted flex-1 truncate pr-2 label-16-regular md:label-14-regular"
|
|
88
|
-
:class="{
|
|
105
|
+
:class="{
|
|
106
|
+
'text-content-on-surface-muted group-data-[invalid=true]/field:text-border-input-error':
|
|
107
|
+
fileDisplayValue === '' && !isInvalid,
|
|
108
|
+
'text-border-input-error': fileDisplayValue === '' && isInvalid,
|
|
109
|
+
}"
|
|
89
110
|
:aria-controls="fileInputId"
|
|
90
111
|
>
|
|
91
112
|
{{ fileDisplayValue || filePlaceholder }}
|