@boostdev/design-system-components 1.1.0 → 1.1.2
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/AGENTS.md +46 -5
- package/dist/client.cjs +206 -113
- package/dist/client.css +664 -624
- package/dist/client.d.cts +9 -3
- package/dist/client.d.ts +9 -3
- package/dist/client.js +241 -149
- package/dist/index.cjs +206 -113
- package/dist/index.css +664 -624
- package/dist/index.d.cts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +241 -149
- package/dist/web-components/chunk-2QA62WCQ.js +48 -0
- package/dist/web-components/chunk-4BX6AWXX.js +146 -0
- package/dist/web-components/chunk-57TRNCWQ.js +93 -0
- package/dist/web-components/chunk-5IPHEONG.js +139 -0
- package/dist/web-components/chunk-5R6IFELV.js +63 -0
- package/dist/web-components/chunk-5TFWOPLH.js +49 -0
- package/dist/web-components/chunk-6I3CFC26.js +89 -0
- package/dist/web-components/chunk-6T3RKUKG.js +65 -0
- package/dist/web-components/chunk-7FMR53BW.js +127 -0
- package/dist/web-components/chunk-A67LCT7C.js +134 -0
- package/dist/web-components/chunk-AGKJTMJI.js +56 -0
- package/dist/web-components/chunk-BQLZ7I4G.js +56 -0
- package/dist/web-components/chunk-CAPI25CU.js +53 -0
- package/dist/web-components/chunk-CJ5ZOO42.js +229 -0
- package/dist/web-components/chunk-CR5PGUHV.js +109 -0
- package/dist/web-components/chunk-ECW3HHWA.js +185 -0
- package/dist/web-components/chunk-HGBNDR22.js +98 -0
- package/dist/web-components/chunk-IK3PTFZ4.js +133 -0
- package/dist/web-components/chunk-IQGLIQSO.js +188 -0
- package/dist/web-components/chunk-ITHLKR7Q.js +105 -0
- package/dist/web-components/chunk-K5CE6HSB.js +169 -0
- package/dist/web-components/chunk-L3XHOMN6.js +111 -0
- package/dist/{web-components.js → web-components/chunk-LGEZYFUU.js} +62 -834
- package/dist/web-components/chunk-LSC4N56Q.js +168 -0
- package/dist/web-components/chunk-LY62SAVN.js +64 -0
- package/dist/web-components/chunk-O4UFI2RX.js +244 -0
- package/dist/web-components/chunk-O7I63SQX.js +124 -0
- package/dist/web-components/chunk-OHUTLSIQ.js +69 -0
- package/dist/web-components/chunk-OQTRTMAB.js +27 -0
- package/dist/web-components/chunk-OTX4COSV.js +187 -0
- package/dist/web-components/chunk-PY62FTRW.js +179 -0
- package/dist/web-components/chunk-Q4T5BJT6.js +94 -0
- package/dist/web-components/chunk-QDRH46TF.js +281 -0
- package/dist/web-components/chunk-QDST57JC.js +119 -0
- package/dist/web-components/chunk-QPOKHLMQ.js +45 -0
- package/dist/web-components/chunk-SOQQ7RVJ.js +88 -0
- package/dist/web-components/chunk-UFFCKVZE.js +149 -0
- package/dist/web-components/chunk-VM3YHGQ2.js +152 -0
- package/dist/web-components/chunk-VMMVWLXL.js +53 -0
- package/dist/web-components/chunk-VSS5ITNE.js +109 -0
- package/dist/web-components/chunk-XIENXR7H.js +118 -0
- package/dist/web-components/chunk-Y4MAXTMA.js +80 -0
- package/dist/web-components/chunk-YLVTEY23.js +165 -0
- package/dist/web-components/globals.d.ts +2 -0
- package/dist/web-components/globals.js +1 -0
- package/dist/web-components/index.d.ts +41 -0
- package/dist/web-components/index.js +165 -0
- package/dist/web-components/interaction/bds-accordion-item.d.ts +54 -0
- package/dist/web-components/interaction/bds-accordion-item.js +7 -0
- package/dist/web-components/interaction/bds-accordion.d.ts +50 -0
- package/dist/web-components/interaction/bds-accordion.js +7 -0
- package/dist/web-components/interaction/bds-button.d.ts +100 -0
- package/dist/web-components/interaction/bds-button.js +7 -0
- package/dist/web-components/interaction/bds-collapsible.d.ts +52 -0
- package/dist/web-components/interaction/bds-collapsible.js +7 -0
- package/dist/web-components/interaction/bds-dialog.d.ts +56 -0
- package/dist/web-components/interaction/bds-dialog.js +7 -0
- package/dist/web-components/interaction/bds-drawer.d.ts +64 -0
- package/dist/web-components/interaction/bds-drawer.js +7 -0
- package/dist/web-components/interaction/bds-popover.d.ts +62 -0
- package/dist/web-components/interaction/bds-popover.js +7 -0
- package/dist/web-components/interaction/bds-skip-link.d.ts +36 -0
- package/dist/web-components/interaction/bds-skip-link.js +7 -0
- package/dist/web-components/interaction/bds-tab-panel.d.ts +26 -0
- package/dist/web-components/interaction/bds-tab-panel.js +7 -0
- package/dist/web-components/interaction/bds-tab.d.ts +45 -0
- package/dist/web-components/interaction/bds-tab.js +7 -0
- package/dist/web-components/interaction/bds-tabs.d.ts +46 -0
- package/dist/web-components/interaction/bds-tabs.js +7 -0
- package/dist/web-components/interaction/bds-toast-provider.d.ts +57 -0
- package/dist/web-components/interaction/bds-toast-provider.js +7 -0
- package/dist/web-components/interaction/bds-tooltip.d.ts +50 -0
- package/dist/web-components/interaction/bds-tooltip.js +7 -0
- package/dist/web-components/interaction/form/bds-checkbox.d.ts +70 -0
- package/dist/web-components/interaction/form/bds-checkbox.js +7 -0
- package/dist/web-components/interaction/form/bds-combobox.d.ts +84 -0
- package/dist/web-components/interaction/form/bds-combobox.js +7 -0
- package/dist/web-components/interaction/form/bds-file-input.d.ts +62 -0
- package/dist/web-components/interaction/form/bds-file-input.js +7 -0
- package/dist/web-components/interaction/form/bds-number-input.d.ts +68 -0
- package/dist/web-components/interaction/form/bds-number-input.js +7 -0
- package/dist/web-components/interaction/form/bds-radio.d.ts +68 -0
- package/dist/web-components/interaction/form/bds-radio.js +7 -0
- package/dist/web-components/interaction/form/bds-segmented-control.d.ts +71 -0
- package/dist/web-components/interaction/form/bds-segmented-control.js +7 -0
- package/dist/web-components/interaction/form/bds-select.d.ts +79 -0
- package/dist/web-components/interaction/form/bds-select.js +7 -0
- package/dist/web-components/interaction/form/bds-slider.d.ts +70 -0
- package/dist/web-components/interaction/form/bds-slider.js +7 -0
- package/dist/web-components/interaction/form/bds-switch.d.ts +67 -0
- package/dist/web-components/interaction/form/bds-switch.js +7 -0
- package/dist/web-components/interaction/form/bds-textarea.d.ts +70 -0
- package/dist/web-components/interaction/form/bds-textarea.js +7 -0
- package/dist/web-components/ui/bds-alert.d.ts +66 -0
- package/dist/web-components/ui/bds-alert.js +7 -0
- package/dist/web-components/ui/bds-avatar.d.ts +50 -0
- package/dist/web-components/ui/bds-avatar.js +7 -0
- package/dist/web-components/ui/bds-badge.d.ts +35 -0
- package/dist/web-components/ui/bds-badge.js +7 -0
- package/dist/web-components/ui/bds-breadcrumb.d.ts +35 -0
- package/dist/web-components/ui/bds-breadcrumb.js +7 -0
- package/dist/web-components/ui/bds-card.d.ts +72 -0
- package/dist/web-components/ui/bds-card.js +7 -0
- package/dist/web-components/ui/bds-description-list.d.ts +42 -0
- package/dist/web-components/ui/bds-description-list.js +7 -0
- package/dist/web-components/ui/bds-icon-wrapper.d.ts +39 -0
- package/dist/web-components/ui/bds-icon-wrapper.js +7 -0
- package/dist/web-components/ui/bds-link.d.ts +59 -0
- package/dist/web-components/ui/bds-link.js +7 -0
- package/dist/web-components/ui/bds-loading.d.ts +32 -0
- package/dist/web-components/ui/bds-loading.js +7 -0
- package/dist/web-components/ui/bds-notification-banner.d.ts +61 -0
- package/dist/web-components/ui/bds-notification-banner.js +7 -0
- package/dist/web-components/ui/bds-progress-circle.d.ts +53 -0
- package/dist/web-components/ui/bds-progress-circle.js +7 -0
- package/dist/web-components/ui/bds-progress.d.ts +54 -0
- package/dist/web-components/ui/bds-progress.js +7 -0
- package/dist/web-components/ui/bds-rating.d.ts +36 -0
- package/dist/web-components/ui/bds-rating.js +7 -0
- package/dist/web-components/ui/bds-section-header.d.ts +53 -0
- package/dist/web-components/ui/bds-section-header.js +8 -0
- package/dist/web-components/ui/bds-separator.d.ts +32 -0
- package/dist/web-components/ui/bds-separator.js +7 -0
- package/dist/web-components/ui/bds-skeleton.d.ts +22 -0
- package/dist/web-components/ui/bds-skeleton.js +7 -0
- package/dist/web-components/ui/bds-typography.d.ts +44 -0
- package/dist/web-components/ui/bds-typography.js +8 -0
- package/package.json +169 -4
- package/src/components/interaction/Button/Button.module.css +1 -1
- package/src/components/interaction/Button/Button.native.mdx +72 -0
- package/src/components/interaction/Command/Command.module.css +7 -7
- package/src/components/interaction/Command/Command.spec.tsx +37 -0
- package/src/components/interaction/Command/Command.tsx +37 -2
- package/src/components/interaction/Dialog/Dialog.module.css +10 -13
- package/src/components/interaction/Dialog/Dialog.spec.tsx +53 -1
- package/src/components/interaction/Dialog/Dialog.stories.tsx +17 -0
- package/src/components/interaction/Dialog/Dialog.tsx +50 -16
- package/src/components/interaction/Drawer/Drawer.module.css +11 -11
- package/src/components/interaction/Drawer/Drawer.spec.tsx +48 -1
- package/src/components/interaction/Drawer/Drawer.tsx +38 -4
- package/src/components/interaction/DropdownMenu/DropdownMenu.module.css +6 -6
- package/src/components/interaction/Popover/Popover.module.css +74 -15
- package/src/components/interaction/Popover/Popover.spec.tsx +94 -59
- package/src/components/interaction/Popover/Popover.tsx +44 -60
- package/src/components/interaction/Toast/Toast.module.css +7 -7
- package/src/components/interaction/form/Checkbox/Checkbox.module.css +6 -6
- package/src/components/interaction/form/Checkbox/Checkbox.native.mdx +74 -0
- package/src/components/interaction/form/Combobox/Combobox.module.css +7 -8
- package/src/components/interaction/form/FileInput/FileInput.module.css +4 -4
- package/src/components/interaction/form/NumberInput/NumberInput.module.css +1 -1
- package/src/components/interaction/form/Radio/Radio.module.css +6 -6
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.module.css +5 -6
- package/src/components/interaction/form/Select/Select.module.css +3 -3
- package/src/components/interaction/form/Slider/Slider.module.css +6 -6
- package/src/components/interaction/form/Switch/Switch.module.css +8 -8
- package/src/components/interaction/form/Textarea/Textarea.module.css +1 -1
- package/src/components/layout/IconWrapper/IconWrapper.module.css +2 -2
- package/src/components/ui/Accordion/Accordion.module.css +5 -5
- package/src/components/ui/Alert/Alert.native.mdx +62 -0
- package/src/components/ui/Avatar/Avatar.native.mdx +50 -0
- package/src/components/ui/Badge/Badge.native.mdx +54 -0
- package/src/components/ui/Calendar/Calendar.module.css +7 -7
- package/src/components/ui/Carousel/Carousel.module.css +5 -5
- package/src/components/ui/Collapsible/Collapsible.module.css +4 -4
- package/src/components/ui/Link/Link.module.css +2 -2
- package/src/components/ui/Loading/Loading.module.css +7 -7
- package/src/components/ui/NotificationBanner/NotificationBanner.module.css +3 -3
- package/src/components/ui/Pagination/Pagination.module.css +6 -6
- package/src/components/ui/Progress/Progress.module.css +5 -5
- package/src/components/ui/Separator/Separator.module.css +3 -3
- package/src/components/ui/Skeleton/Skeleton.module.css +1 -1
- package/src/components/ui/Table/Table.module.css +9 -9
- package/src/components/ui/Tabs/Tabs.module.css +3 -3
- package/src/components/ui/Tooltip/Tooltip.module.css +8 -8
- package/src/components/ui/Typography/Typography.native.mdx +56 -0
- package/src/polyfill-invoker-commands.ts +68 -0
- package/src/react-augment.d.ts +19 -0
- package/src/stories/ReactNative.mdx +121 -0
- package/src/web-components/index.ts +47 -0
- package/src/web-components/interaction/BdsButton.mdx +106 -0
- package/src/web-components/interaction/BdsPopover.mdx +120 -0
- package/src/web-components/interaction/BdsToastProvider.mdx +94 -0
- package/src/web-components/interaction/bds-accordion-item.spec.ts +75 -0
- package/src/web-components/interaction/bds-accordion-item.ts +181 -0
- package/src/web-components/interaction/bds-accordion.spec.ts +73 -0
- package/src/web-components/interaction/bds-accordion.ts +99 -0
- package/src/web-components/interaction/bds-collapsible.spec.ts +56 -0
- package/src/web-components/interaction/bds-collapsible.ts +170 -0
- package/src/web-components/interaction/bds-dialog.spec.ts +119 -0
- package/src/web-components/interaction/bds-dialog.ts +224 -0
- package/src/web-components/interaction/bds-drawer.spec.ts +113 -0
- package/src/web-components/interaction/bds-drawer.ts +266 -0
- package/src/web-components/interaction/bds-popover.spec.ts +49 -1
- package/src/web-components/interaction/bds-popover.ts +12 -0
- package/src/web-components/interaction/bds-skip-link.spec.ts +42 -0
- package/src/web-components/interaction/bds-skip-link.ts +74 -0
- package/src/web-components/interaction/bds-tab-panel.spec.ts +32 -0
- package/src/web-components/interaction/bds-tab-panel.ts +38 -0
- package/src/web-components/interaction/bds-tab.spec.ts +71 -0
- package/src/web-components/interaction/bds-tab.ts +110 -0
- package/src/web-components/interaction/bds-tabs.spec.ts +120 -0
- package/src/web-components/interaction/bds-tabs.ts +152 -0
- package/src/web-components/interaction/bds-tooltip.spec.ts +49 -0
- package/src/web-components/interaction/bds-tooltip.ts +127 -0
- package/src/web-components/interaction/form/bds-checkbox.spec.ts +63 -0
- package/src/web-components/interaction/form/bds-checkbox.ts +168 -0
- package/src/web-components/interaction/form/bds-combobox.spec.ts +117 -0
- package/src/web-components/interaction/form/bds-combobox.ts +336 -0
- package/src/web-components/interaction/form/bds-file-input.spec.ts +58 -0
- package/src/web-components/interaction/form/bds-file-input.ts +209 -0
- package/src/web-components/interaction/form/bds-number-input.spec.ts +87 -0
- package/src/web-components/interaction/form/bds-number-input.ts +221 -0
- package/src/web-components/interaction/form/bds-radio.spec.ts +70 -0
- package/src/web-components/interaction/form/bds-radio.ts +157 -0
- package/src/web-components/interaction/form/bds-segmented-control.spec.ts +74 -0
- package/src/web-components/interaction/form/bds-segmented-control.ts +211 -0
- package/src/web-components/interaction/form/bds-select.spec.ts +74 -0
- package/src/web-components/interaction/form/bds-select.ts +190 -0
- package/src/web-components/interaction/form/bds-slider.spec.ts +41 -0
- package/src/web-components/interaction/form/bds-slider.ts +162 -0
- package/src/web-components/interaction/form/bds-switch.spec.ts +62 -0
- package/src/web-components/interaction/form/bds-switch.ts +166 -0
- package/src/web-components/interaction/form/bds-textarea.spec.ts +55 -0
- package/src/web-components/interaction/form/bds-textarea.ts +143 -0
- package/src/web-components/test/helpers.ts +8 -0
- package/src/web-components/ui/BdsAlert.mdx +90 -0
- package/src/web-components/ui/BdsBadge.mdx +74 -0
- package/src/web-components/ui/bds-avatar.spec.ts +75 -0
- package/src/web-components/ui/bds-avatar.ts +122 -0
- package/src/web-components/ui/bds-breadcrumb.spec.ts +55 -0
- package/src/web-components/ui/bds-breadcrumb.ts +114 -0
- package/src/web-components/ui/bds-card.spec.ts +70 -0
- package/src/web-components/ui/bds-card.ts +156 -0
- package/src/web-components/ui/bds-description-list.spec.ts +36 -0
- package/src/web-components/ui/bds-description-list.ts +79 -0
- package/src/web-components/ui/bds-icon-wrapper.spec.ts +21 -0
- package/src/web-components/ui/bds-icon-wrapper.ts +68 -0
- package/src/web-components/ui/bds-link.spec.ts +72 -0
- package/src/web-components/ui/bds-link.ts +138 -0
- package/src/web-components/ui/bds-loading.spec.ts +38 -0
- package/src/web-components/ui/bds-loading.ts +76 -0
- package/src/web-components/ui/bds-notification-banner.spec.ts +82 -0
- package/src/web-components/ui/bds-notification-banner.ts +185 -0
- package/src/web-components/ui/bds-progress-circle.spec.ts +58 -0
- package/src/web-components/ui/bds-progress-circle.ts +142 -0
- package/src/web-components/ui/bds-progress.spec.ts +66 -0
- package/src/web-components/ui/bds-progress.ts +127 -0
- package/src/web-components/ui/bds-rating.spec.ts +70 -0
- package/src/web-components/ui/bds-rating.ts +80 -0
- package/src/web-components/ui/bds-section-header.spec.ts +57 -0
- package/src/web-components/ui/bds-section-header.ts +96 -0
- package/src/web-components/ui/bds-separator.spec.ts +50 -0
- package/src/web-components/ui/bds-separator.ts +66 -0
- package/src/web-components/ui/bds-skeleton.spec.ts +22 -0
- package/src/web-components/ui/bds-skeleton.ts +55 -0
- package/src/web-components/ui/bds-typography.spec.ts +76 -0
- package/src/web-components/ui/bds-typography.ts +112 -0
- package/dist/web-components.d.ts +0 -303
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { LitElement, css, html } from 'lit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `<bds-checkbox>` — form-associated Checkbox custom element.
|
|
5
|
+
*
|
|
6
|
+
* Participates in HTML forms via the Form-Associated Custom Elements API
|
|
7
|
+
* (`ElementInternals`). Native browser validation (required, etc.) works
|
|
8
|
+
* without any wrapper.
|
|
9
|
+
*
|
|
10
|
+
* Attributes:
|
|
11
|
+
* name — form field name
|
|
12
|
+
* value — submitted value when checked (default: "on")
|
|
13
|
+
* checked — boolean; whether the checkbox is checked
|
|
14
|
+
* required — boolean
|
|
15
|
+
* disabled — boolean
|
|
16
|
+
*
|
|
17
|
+
* Slots:
|
|
18
|
+
* (default) — label text
|
|
19
|
+
*
|
|
20
|
+
* Events:
|
|
21
|
+
* change — native change event (forwarded from inner input)
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* <bds-checkbox name="agree" value="yes" required>I agree</bds-checkbox>
|
|
25
|
+
*/
|
|
26
|
+
export class BdsCheckbox extends LitElement {
|
|
27
|
+
static formAssociated = true;
|
|
28
|
+
|
|
29
|
+
static styles = css`
|
|
30
|
+
:host {
|
|
31
|
+
display: inline-flex;
|
|
32
|
+
align-items: flex-start;
|
|
33
|
+
gap: var(--bds-space_xs);
|
|
34
|
+
cursor: pointer;
|
|
35
|
+
font-size: var(--bds-font_size--body);
|
|
36
|
+
font-family: var(--bds-font_family--body);
|
|
37
|
+
color: var(--bds-color_on-bg);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
:host([disabled]) {
|
|
41
|
+
opacity: 0.5;
|
|
42
|
+
cursor: not-allowed;
|
|
43
|
+
pointer-events: none;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.input {
|
|
47
|
+
--inputSize: calc(var(--bds-space_s) * 2);
|
|
48
|
+
margin-block-start: 0.25em;
|
|
49
|
+
inline-size: var(--inputSize);
|
|
50
|
+
block-size: var(--inputSize);
|
|
51
|
+
flex-shrink: 0;
|
|
52
|
+
--bdc_color: currentcolor;
|
|
53
|
+
--bdc-outline_radius: var(--bds-border_radius--xs);
|
|
54
|
+
|
|
55
|
+
outline: var(--bdc-outline_width) solid var(--bdc_color);
|
|
56
|
+
outline-offset: var(--bdc-outline_offset);
|
|
57
|
+
border-radius: var(--checkbox_radius, var(--bdc-outline_radius));
|
|
58
|
+
box-shadow: var(--checkbox_shadow, var(--bdc-outline_shadow));
|
|
59
|
+
border: none;
|
|
60
|
+
appearance: none;
|
|
61
|
+
background-color: var(--checkbox_color_bg, var(--bds-color_bg));
|
|
62
|
+
cursor: pointer;
|
|
63
|
+
position: relative;
|
|
64
|
+
transition: --bdc_color 0.3s ease, background-color 0.3s ease;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.input:checked {
|
|
68
|
+
background-color: var(--checkbox_color-active, var(--bdc-color_active));
|
|
69
|
+
--bdc_color: var(--checkbox_color-active, var(--bdc-color_active));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.input:checked::after {
|
|
73
|
+
content: '';
|
|
74
|
+
position: absolute;
|
|
75
|
+
inset-inline-start: 0.6em;
|
|
76
|
+
inset-block-start: 0.2em;
|
|
77
|
+
inline-size: 0.5em;
|
|
78
|
+
block-size: 1em;
|
|
79
|
+
border: solid var(--checkbox_color-on-active, var(--bdc-color_on-active));
|
|
80
|
+
border-width: 0 2px 2px 0;
|
|
81
|
+
transform: rotate(45deg);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.input:focus-visible {
|
|
85
|
+
outline: var(--bds-outline_default);
|
|
86
|
+
outline-offset: var(--bds-outline_offset);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
label {
|
|
90
|
+
cursor: pointer;
|
|
91
|
+
flex: 1;
|
|
92
|
+
}
|
|
93
|
+
`;
|
|
94
|
+
|
|
95
|
+
static properties = {
|
|
96
|
+
name: { type: String, reflect: true },
|
|
97
|
+
value: { type: String },
|
|
98
|
+
checked: { type: Boolean, reflect: true },
|
|
99
|
+
required: { type: Boolean, reflect: true },
|
|
100
|
+
disabled: { type: Boolean, reflect: true },
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
declare name: string;
|
|
104
|
+
declare value: string;
|
|
105
|
+
declare checked: boolean;
|
|
106
|
+
declare required: boolean;
|
|
107
|
+
declare disabled: boolean;
|
|
108
|
+
|
|
109
|
+
private _internals!: ElementInternals;
|
|
110
|
+
private readonly _uid = Math.random().toString(36).slice(2, 8);
|
|
111
|
+
|
|
112
|
+
constructor() {
|
|
113
|
+
super();
|
|
114
|
+
this._internals = this.attachInternals();
|
|
115
|
+
this.name = '';
|
|
116
|
+
this.value = 'on';
|
|
117
|
+
this.checked = false;
|
|
118
|
+
this.required = false;
|
|
119
|
+
this.disabled = false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
updated(changed: Map<string, unknown>) {
|
|
123
|
+
super.updated(changed);
|
|
124
|
+
if (changed.has('checked') || changed.has('value')) {
|
|
125
|
+
this._internals.setFormValue?.(this.checked ? this.value : null);
|
|
126
|
+
}
|
|
127
|
+
if (changed.has('required')) {
|
|
128
|
+
if (this.required && !this.checked) {
|
|
129
|
+
this._internals.setValidity?.({ valueMissing: true }, 'Required');
|
|
130
|
+
} else {
|
|
131
|
+
this._internals.setValidity?.({});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
formResetCallback() {
|
|
137
|
+
this.checked = false;
|
|
138
|
+
this._internals.setFormValue?.(null);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private _handleChange(e: Event) {
|
|
142
|
+
this.checked = (e.target as HTMLInputElement).checked;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
render() {
|
|
146
|
+
const id = `bds-checkbox-${this._uid}`;
|
|
147
|
+
return html`
|
|
148
|
+
<input
|
|
149
|
+
id=${id}
|
|
150
|
+
type="checkbox"
|
|
151
|
+
class="input"
|
|
152
|
+
.checked=${this.checked}
|
|
153
|
+
?required=${this.required}
|
|
154
|
+
?disabled=${this.disabled}
|
|
155
|
+
@change=${this._handleChange}
|
|
156
|
+
/>
|
|
157
|
+
<label for=${id}><slot></slot></label>
|
|
158
|
+
`;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
customElements.define('bds-checkbox', BdsCheckbox);
|
|
163
|
+
|
|
164
|
+
declare global {
|
|
165
|
+
interface HTMLElementTagNameMap {
|
|
166
|
+
'bds-checkbox': BdsCheckbox;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { fixture, cleanup } from '../../test/helpers';
|
|
2
|
+
import { BdsCombobox } from './bds-combobox';
|
|
3
|
+
|
|
4
|
+
const OPTIONS = JSON.stringify([
|
|
5
|
+
{ value: 'nl', label: 'Netherlands' },
|
|
6
|
+
{ value: 'be', label: 'Belgium' },
|
|
7
|
+
{ value: 'de', label: 'Germany', disabled: true },
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
describe('bds-combobox', () => {
|
|
11
|
+
it('is registered as a custom element', () => {
|
|
12
|
+
expect(customElements.get('bds-combobox')).toBe(BdsCombobox);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('renders a text input with role="combobox"', async () => {
|
|
16
|
+
const el = await fixture(`<bds-combobox name="country" options='${OPTIONS}'></bds-combobox>`);
|
|
17
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
18
|
+
expect(input).not.toBeNull();
|
|
19
|
+
expect(input.getAttribute('role')).toBe('combobox');
|
|
20
|
+
cleanup(el);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('forwards placeholder to the input', async () => {
|
|
24
|
+
const el = await fixture(`<bds-combobox name="country" placeholder="Search…" options='${OPTIONS}'></bds-combobox>`);
|
|
25
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
26
|
+
expect(input.placeholder).toBe('Search…');
|
|
27
|
+
cleanup(el);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('input is disabled when disabled attribute is set', async () => {
|
|
31
|
+
const el = await fixture(`<bds-combobox name="country" disabled options='${OPTIONS}'></bds-combobox>`);
|
|
32
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
33
|
+
expect(input.disabled).toBe(true);
|
|
34
|
+
cleanup(el);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('shows listbox when input is focused', async () => {
|
|
38
|
+
const el = await fixture(`<bds-combobox name="country" options='${OPTIONS}'></bds-combobox>`);
|
|
39
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
40
|
+
input.dispatchEvent(new Event('focus'));
|
|
41
|
+
await el.updateComplete;
|
|
42
|
+
expect(el.shadowRoot!.querySelector('[role="listbox"]')).not.toBeNull();
|
|
43
|
+
cleanup(el);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('renders options in the listbox', async () => {
|
|
47
|
+
const el = await fixture(`<bds-combobox name="country" options='${OPTIONS}'></bds-combobox>`);
|
|
48
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
49
|
+
input.dispatchEvent(new Event('focus'));
|
|
50
|
+
await el.updateComplete;
|
|
51
|
+
const listItems = el.shadowRoot!.querySelectorAll('[role="option"]');
|
|
52
|
+
expect(listItems.length).toBe(3);
|
|
53
|
+
cleanup(el);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('selects an option on mousedown', async () => {
|
|
57
|
+
const el = await fixture(`<bds-combobox name="country" options='${OPTIONS}'></bds-combobox>`) as BdsCombobox;
|
|
58
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
59
|
+
input.dispatchEvent(new Event('focus'));
|
|
60
|
+
await el.updateComplete;
|
|
61
|
+
const option = el.shadowRoot!.querySelector<HTMLElement>('[role="option"]')!;
|
|
62
|
+
option.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
|
|
63
|
+
expect(el.value).toBe('nl');
|
|
64
|
+
cleanup(el);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('fires bds-change when an option is selected', async () => {
|
|
68
|
+
const el = await fixture(`<bds-combobox name="country" options='${OPTIONS}'></bds-combobox>`);
|
|
69
|
+
const handler = vi.fn();
|
|
70
|
+
el.addEventListener('bds-change', handler);
|
|
71
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
72
|
+
input.dispatchEvent(new Event('focus'));
|
|
73
|
+
await el.updateComplete;
|
|
74
|
+
const option = el.shadowRoot!.querySelector<HTMLElement>('[role="option"]')!;
|
|
75
|
+
option.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
|
|
76
|
+
expect(handler).toHaveBeenCalledOnce();
|
|
77
|
+
expect(handler.mock.calls[0][0].detail).toMatchObject({ value: 'nl' });
|
|
78
|
+
cleanup(el);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('filters options based on input text', async () => {
|
|
82
|
+
const el = await fixture(`<bds-combobox name="country" options='${OPTIONS}'></bds-combobox>`);
|
|
83
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
84
|
+
input.value = 'Neth';
|
|
85
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
86
|
+
await el.updateComplete;
|
|
87
|
+
const options = el.shadowRoot!.querySelectorAll('[role="option"]');
|
|
88
|
+
expect(options.length).toBe(1);
|
|
89
|
+
expect(options[0].textContent?.trim()).toBe('Netherlands');
|
|
90
|
+
cleanup(el);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('shows no results message when filter matches nothing', async () => {
|
|
94
|
+
const el = await fixture(`<bds-combobox name="country" options='${OPTIONS}'></bds-combobox>`);
|
|
95
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
96
|
+
input.value = 'zzz';
|
|
97
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
98
|
+
await el.updateComplete;
|
|
99
|
+
expect(el.shadowRoot!.querySelector('.no-results')).not.toBeNull();
|
|
100
|
+
cleanup(el);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('closes listbox on Escape key', async () => {
|
|
104
|
+
const el = await fixture(`<bds-combobox name="country" options='${OPTIONS}'></bds-combobox>`);
|
|
105
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
106
|
+
input.dispatchEvent(new Event('focus'));
|
|
107
|
+
await el.updateComplete;
|
|
108
|
+
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
|
|
109
|
+
await el.updateComplete;
|
|
110
|
+
expect(el.shadowRoot!.querySelector('[role="listbox"]')).toBeNull();
|
|
111
|
+
cleanup(el);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('is form-associated', () => {
|
|
115
|
+
expect(BdsCombobox.formAssociated).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { LitElement, css, html } from 'lit';
|
|
2
|
+
|
|
3
|
+
export interface ComboboxOption {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `<bds-combobox>` — form-associated Combobox (autocomplete) custom element.
|
|
11
|
+
*
|
|
12
|
+
* Renders a text input with a filterable dropdown. Keyboard navigation:
|
|
13
|
+
* ArrowDown/ArrowUp to move focus, Enter to select, Escape to close.
|
|
14
|
+
*
|
|
15
|
+
* Attributes:
|
|
16
|
+
* name — form field name
|
|
17
|
+
* value — currently selected value
|
|
18
|
+
* options — JSON array of `{ value, label, disabled? }` option objects
|
|
19
|
+
* placeholder — input placeholder text
|
|
20
|
+
* disabled — boolean
|
|
21
|
+
*
|
|
22
|
+
* Events:
|
|
23
|
+
* bds-change — fired with `{ detail: { value, label } }` when an option is selected
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* <bds-combobox
|
|
27
|
+
* name="country"
|
|
28
|
+
* placeholder="Search…"
|
|
29
|
+
* options='[{"value":"nl","label":"Netherlands"},{"value":"be","label":"Belgium"}]'
|
|
30
|
+
* ></bds-combobox>
|
|
31
|
+
*/
|
|
32
|
+
export class BdsCombobox extends LitElement {
|
|
33
|
+
static formAssociated = true;
|
|
34
|
+
|
|
35
|
+
static styles = css`
|
|
36
|
+
:host {
|
|
37
|
+
display: block;
|
|
38
|
+
position: relative;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
:host([disabled]) {
|
|
42
|
+
opacity: 0.5;
|
|
43
|
+
pointer-events: none;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.wrapper {
|
|
47
|
+
position: relative;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.input {
|
|
51
|
+
inline-size: 100%;
|
|
52
|
+
font-family: var(--bds-font_family--body);
|
|
53
|
+
font-size: var(--bds-font_size--body);
|
|
54
|
+
padding: var(--bds-space_s);
|
|
55
|
+
padding-inline-end: var(--bds-space_xl);
|
|
56
|
+
border: none;
|
|
57
|
+
--bdc_color: currentcolor;
|
|
58
|
+
--bdc-outline_radius: var(--bds-border_radius--xs);
|
|
59
|
+
|
|
60
|
+
outline: var(--bdc-outline_width) solid var(--bdc_color);
|
|
61
|
+
outline-offset: var(--bdc-outline_offset);
|
|
62
|
+
border-radius: var(--combobox_radius, var(--bdc-outline_radius));
|
|
63
|
+
box-shadow: var(--combobox_shadow, var(--bdc-outline_shadow));
|
|
64
|
+
background-color: var(--combobox_color_bg, var(--bds-color_bg));
|
|
65
|
+
color: var(--combobox_color, var(--bds-color_on-bg));
|
|
66
|
+
box-sizing: border-box;
|
|
67
|
+
transition: --bdc_color var(--bds-animation_transition-duration) var(--bds-animation_easing);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.input:focus {
|
|
71
|
+
--bdc_color: var(--bdc_color--focus);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.input:focus-visible {
|
|
75
|
+
outline: var(--bds-outline_default);
|
|
76
|
+
outline-offset: var(--bds-outline_offset);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.chevron {
|
|
80
|
+
position: absolute;
|
|
81
|
+
inset-inline-end: var(--bds-space_s);
|
|
82
|
+
inset-block-start: 50%;
|
|
83
|
+
transform: translateY(-50%);
|
|
84
|
+
pointer-events: none;
|
|
85
|
+
inline-size: 1rem;
|
|
86
|
+
block-size: 1rem;
|
|
87
|
+
color: currentcolor;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.chevron svg {
|
|
91
|
+
inline-size: 100%;
|
|
92
|
+
block-size: 100%;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.listbox {
|
|
96
|
+
position: absolute;
|
|
97
|
+
inset-block-start: calc(100% + var(--bds-space_xs));
|
|
98
|
+
inset-inline-start: 0;
|
|
99
|
+
inline-size: 100%;
|
|
100
|
+
max-block-size: 15rem;
|
|
101
|
+
overflow-y: auto;
|
|
102
|
+
background-color: var(--combobox_list-bg, var(--bds-color_bg));
|
|
103
|
+
border-radius: var(--bds-border_radius--s);
|
|
104
|
+
box-shadow: var(--bds-shadow_m);
|
|
105
|
+
z-index: var(--combobox_z-index, 100);
|
|
106
|
+
padding-block: var(--bds-space_xs);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.option {
|
|
110
|
+
display: block;
|
|
111
|
+
padding: var(--bds-space_s) var(--bds-space_m);
|
|
112
|
+
cursor: pointer;
|
|
113
|
+
font-family: var(--bds-font_family--body);
|
|
114
|
+
font-size: var(--bds-font_size--body);
|
|
115
|
+
color: var(--bds-color_on-bg);
|
|
116
|
+
transition: background-color var(--bds-animation_transition-duration) var(--bds-animation_easing);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.option:hover,
|
|
120
|
+
.option[aria-selected='true'] {
|
|
121
|
+
background-color: var(--bds-color_bg--subtle);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.option[aria-disabled='true'] {
|
|
125
|
+
opacity: 0.4;
|
|
126
|
+
cursor: not-allowed;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.option.--focused {
|
|
130
|
+
background-color: var(--bds-color_bg--subtle);
|
|
131
|
+
outline: none;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.no-results {
|
|
135
|
+
padding: var(--bds-space_s) var(--bds-space_m);
|
|
136
|
+
font-family: var(--bds-font_family--body);
|
|
137
|
+
font-size: var(--bds-font_size--body--s);
|
|
138
|
+
color: var(--bds-color_on-bg--subtle);
|
|
139
|
+
}
|
|
140
|
+
`;
|
|
141
|
+
|
|
142
|
+
static properties = {
|
|
143
|
+
name: { type: String, reflect: true },
|
|
144
|
+
value: { type: String },
|
|
145
|
+
options: { type: String },
|
|
146
|
+
placeholder: { type: String },
|
|
147
|
+
disabled: { type: Boolean, reflect: true },
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
declare name: string;
|
|
151
|
+
declare value: string;
|
|
152
|
+
declare options: string;
|
|
153
|
+
declare placeholder: string;
|
|
154
|
+
declare disabled: boolean;
|
|
155
|
+
|
|
156
|
+
private _internals!: ElementInternals;
|
|
157
|
+
private _open = false;
|
|
158
|
+
private _query = '';
|
|
159
|
+
private _focusedIndex = -1;
|
|
160
|
+
|
|
161
|
+
constructor() {
|
|
162
|
+
super();
|
|
163
|
+
this._internals = this.attachInternals();
|
|
164
|
+
this.name = '';
|
|
165
|
+
this.value = '';
|
|
166
|
+
this.options = '[]';
|
|
167
|
+
this.placeholder = '';
|
|
168
|
+
this.disabled = false;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private get _options(): ComboboxOption[] {
|
|
172
|
+
try {
|
|
173
|
+
return JSON.parse(this.options) as ComboboxOption[];
|
|
174
|
+
} catch {
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private get _filtered(): ComboboxOption[] {
|
|
180
|
+
const q = this._query.toLowerCase();
|
|
181
|
+
return q
|
|
182
|
+
? this._options.filter(o => o.label.toLowerCase().includes(q))
|
|
183
|
+
: this._options;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private get _displayLabel(): string {
|
|
187
|
+
if (this.value) {
|
|
188
|
+
return this._options.find(o => o.value === this.value)?.label ?? '';
|
|
189
|
+
}
|
|
190
|
+
return '';
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
updated(changed: Map<string, unknown>) {
|
|
194
|
+
super.updated(changed);
|
|
195
|
+
if (changed.has('value')) {
|
|
196
|
+
this._internals.setFormValue?.(this.value || null);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
formResetCallback() {
|
|
201
|
+
this.value = '';
|
|
202
|
+
this._query = '';
|
|
203
|
+
this._open = false;
|
|
204
|
+
this._internals.setFormValue?.(null);
|
|
205
|
+
this.requestUpdate();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private _openList() {
|
|
209
|
+
this._open = true;
|
|
210
|
+
this._focusedIndex = this._filtered.findIndex(o => o.value === this.value);
|
|
211
|
+
this.requestUpdate();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private _closeList() {
|
|
215
|
+
this._open = false;
|
|
216
|
+
this._query = '';
|
|
217
|
+
this._focusedIndex = -1;
|
|
218
|
+
this.requestUpdate();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private _selectOption(opt: ComboboxOption) {
|
|
222
|
+
if (opt.disabled) return;
|
|
223
|
+
this.value = opt.value;
|
|
224
|
+
this._closeList();
|
|
225
|
+
this.dispatchEvent(new CustomEvent('bds-change', {
|
|
226
|
+
bubbles: true,
|
|
227
|
+
composed: true,
|
|
228
|
+
detail: { value: opt.value, label: opt.label },
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private _handleInput(e: Event) {
|
|
233
|
+
this._query = (e.target as HTMLInputElement).value;
|
|
234
|
+
this._open = true;
|
|
235
|
+
this._focusedIndex = -1;
|
|
236
|
+
this.requestUpdate();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private _handleFocus() {
|
|
240
|
+
this._openList();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
private _handleBlur() {
|
|
244
|
+
// Delay close so option clicks register first
|
|
245
|
+
setTimeout(() => {
|
|
246
|
+
this._closeList();
|
|
247
|
+
}, 150);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
private _handleKeydown(e: KeyboardEvent) {
|
|
251
|
+
const filtered = this._filtered;
|
|
252
|
+
if (!this._open) {
|
|
253
|
+
if (e.key === 'ArrowDown' || e.key === 'Enter') {
|
|
254
|
+
e.preventDefault();
|
|
255
|
+
this._openList();
|
|
256
|
+
}
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (e.key === 'ArrowDown') {
|
|
261
|
+
e.preventDefault();
|
|
262
|
+
let next = this._focusedIndex + 1;
|
|
263
|
+
while (next < filtered.length && filtered[next].disabled) next++;
|
|
264
|
+
if (next < filtered.length) this._focusedIndex = next;
|
|
265
|
+
} else if (e.key === 'ArrowUp') {
|
|
266
|
+
e.preventDefault();
|
|
267
|
+
let prev = this._focusedIndex - 1;
|
|
268
|
+
while (prev >= 0 && filtered[prev].disabled) prev--;
|
|
269
|
+
if (prev >= 0) this._focusedIndex = prev;
|
|
270
|
+
} else if (e.key === 'Enter') {
|
|
271
|
+
e.preventDefault();
|
|
272
|
+
if (this._focusedIndex >= 0 && this._focusedIndex < filtered.length) {
|
|
273
|
+
this._selectOption(filtered[this._focusedIndex]);
|
|
274
|
+
}
|
|
275
|
+
} else if (e.key === 'Escape') {
|
|
276
|
+
e.preventDefault();
|
|
277
|
+
this._closeList();
|
|
278
|
+
}
|
|
279
|
+
this.requestUpdate();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
render() {
|
|
283
|
+
const filtered = this._filtered;
|
|
284
|
+
const inputValue = this._open ? this._query : this._displayLabel;
|
|
285
|
+
|
|
286
|
+
return html`
|
|
287
|
+
<div class="wrapper">
|
|
288
|
+
<input
|
|
289
|
+
type="text"
|
|
290
|
+
class="input"
|
|
291
|
+
role="combobox"
|
|
292
|
+
aria-expanded=${this._open}
|
|
293
|
+
aria-autocomplete="list"
|
|
294
|
+
aria-haspopup="listbox"
|
|
295
|
+
name=${this.name}
|
|
296
|
+
placeholder=${this.placeholder}
|
|
297
|
+
.value=${inputValue}
|
|
298
|
+
?disabled=${this.disabled}
|
|
299
|
+
@input=${this._handleInput}
|
|
300
|
+
@focus=${this._handleFocus}
|
|
301
|
+
@blur=${this._handleBlur}
|
|
302
|
+
@keydown=${this._handleKeydown}
|
|
303
|
+
/>
|
|
304
|
+
<span class="chevron" aria-hidden="true">
|
|
305
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
306
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M6 9l6 6 6-6" />
|
|
307
|
+
</svg>
|
|
308
|
+
</span>
|
|
309
|
+
${this._open ? html`
|
|
310
|
+
<ul class="listbox" role="listbox" aria-label="Options">
|
|
311
|
+
${filtered.length === 0
|
|
312
|
+
? html`<li class="no-results">No results</li>`
|
|
313
|
+
: filtered.map((opt, i) => html`
|
|
314
|
+
<li
|
|
315
|
+
class="option ${i === this._focusedIndex ? '--focused' : ''}"
|
|
316
|
+
role="option"
|
|
317
|
+
aria-selected=${opt.value === this.value}
|
|
318
|
+
aria-disabled=${opt.disabled ?? false}
|
|
319
|
+
@mousedown=${(e: Event) => { e.preventDefault(); this._selectOption(opt); }}
|
|
320
|
+
>${opt.label}</li>
|
|
321
|
+
`)
|
|
322
|
+
}
|
|
323
|
+
</ul>
|
|
324
|
+
` : ''}
|
|
325
|
+
</div>
|
|
326
|
+
`;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
customElements.define('bds-combobox', BdsCombobox);
|
|
331
|
+
|
|
332
|
+
declare global {
|
|
333
|
+
interface HTMLElementTagNameMap {
|
|
334
|
+
'bds-combobox': BdsCombobox;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { fixture, cleanup } from '../../test/helpers';
|
|
2
|
+
import { BdsFileInput } from './bds-file-input';
|
|
3
|
+
|
|
4
|
+
describe('bds-file-input', () => {
|
|
5
|
+
it('is registered as a custom element', () => {
|
|
6
|
+
expect(customElements.get('bds-file-input')).toBe(BdsFileInput);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('renders a file input in shadow DOM', async () => {
|
|
10
|
+
const el = await fixture('<bds-file-input name="avatar"></bds-file-input>');
|
|
11
|
+
expect(el.shadowRoot!.querySelector('input[type="file"]')).not.toBeNull();
|
|
12
|
+
cleanup(el);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('renders a drop zone with role="button"', async () => {
|
|
16
|
+
const el = await fixture('<bds-file-input name="avatar"></bds-file-input>');
|
|
17
|
+
expect(el.shadowRoot!.querySelector('[role="button"]')).not.toBeNull();
|
|
18
|
+
cleanup(el);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('drop zone has aria-label="Upload file"', async () => {
|
|
22
|
+
const el = await fixture('<bds-file-input name="avatar"></bds-file-input>');
|
|
23
|
+
const zone = el.shadowRoot!.querySelector('[role="button"]')!;
|
|
24
|
+
expect(zone.getAttribute('aria-label')).toBe('Upload file');
|
|
25
|
+
cleanup(el);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('input is disabled when disabled attribute is set', async () => {
|
|
29
|
+
const el = await fixture('<bds-file-input name="avatar" disabled></bds-file-input>');
|
|
30
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
31
|
+
expect(input.disabled).toBe(true);
|
|
32
|
+
cleanup(el);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('forwards accept attribute to input', async () => {
|
|
36
|
+
const el = await fixture('<bds-file-input name="avatar" accept="image/*"></bds-file-input>');
|
|
37
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
38
|
+
expect(input.accept).toBe('image/*');
|
|
39
|
+
cleanup(el);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('forwards multiple attribute to input', async () => {
|
|
43
|
+
const el = await fixture('<bds-file-input name="files" multiple></bds-file-input>');
|
|
44
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
45
|
+
expect(input.multiple).toBe(true);
|
|
46
|
+
cleanup(el);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('renders slotted label text', async () => {
|
|
50
|
+
const el = await fixture('<bds-file-input name="avatar">Upload photo</bds-file-input>');
|
|
51
|
+
expect(el.textContent?.trim()).toBe('Upload photo');
|
|
52
|
+
cleanup(el);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('is form-associated', () => {
|
|
56
|
+
expect(BdsFileInput.formAssociated).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
});
|