snice 2.1.4 → 2.2.0
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/components/accordion/snice-accordion-item.d.ts +25 -0
- package/dist/components/accordion/snice-accordion-item.js +255 -0
- package/dist/components/accordion/snice-accordion-item.js.map +1 -0
- package/dist/components/accordion/snice-accordion.d.ts +28 -0
- package/dist/components/accordion/snice-accordion.js +206 -0
- package/dist/components/accordion/snice-accordion.js.map +1 -0
- package/dist/components/accordion/snice-accordion.types.d.ts +29 -0
- package/dist/components/alert/snice-alert.d.ts +26 -0
- package/dist/components/alert/snice-alert.js +180 -0
- package/dist/components/alert/snice-alert.js.map +1 -0
- package/{components/alert/snice-alert.types.ts → dist/components/alert/snice-alert.types.d.ts} +8 -9
- package/dist/components/avatar/snice-avatar.d.ts +24 -0
- package/dist/components/avatar/snice-avatar.js +180 -0
- package/dist/components/avatar/snice-avatar.js.map +1 -0
- package/dist/components/avatar/snice-avatar.types.d.ts +12 -0
- package/dist/components/badge/snice-badge.d.ts +25 -0
- package/dist/components/badge/snice-badge.js +169 -0
- package/dist/components/badge/snice-badge.js.map +1 -0
- package/{components/badge/snice-badge.types.ts → dist/components/badge/snice-badge.types.d.ts} +11 -12
- package/dist/components/breadcrumbs/snice-breadcrumbs.d.ts +27 -0
- package/dist/components/breadcrumbs/snice-breadcrumbs.js +214 -0
- package/dist/components/breadcrumbs/snice-breadcrumbs.js.map +1 -0
- package/dist/components/breadcrumbs/snice-breadcrumbs.types.d.ts +23 -0
- package/dist/components/breadcrumbs/snice-crumb.d.ts +9 -0
- package/dist/components/breadcrumbs/snice-crumb.js +63 -0
- package/dist/components/breadcrumbs/snice-crumb.js.map +1 -0
- package/dist/components/button/snice-button.d.ts +32 -0
- package/dist/components/button/snice-button.js +232 -0
- package/dist/components/button/snice-button.js.map +1 -0
- package/dist/components/button/snice-button.types.d.ts +23 -0
- package/dist/components/card/snice-card.d.ts +19 -0
- package/dist/components/card/snice-card.js +136 -0
- package/dist/components/card/snice-card.js.map +1 -0
- package/{components/card/snice-card.types.ts → dist/components/card/snice-card.types.d.ts} +6 -7
- package/dist/components/checkbox/snice-checkbox.d.ts +34 -0
- package/dist/components/checkbox/snice-checkbox.js +286 -0
- package/dist/components/checkbox/snice-checkbox.js.map +1 -0
- package/dist/components/checkbox/snice-checkbox.types.d.ts +20 -0
- package/dist/components/chip/snice-chip.d.ts +28 -0
- package/dist/components/chip/snice-chip.js +199 -0
- package/dist/components/chip/snice-chip.js.map +1 -0
- package/dist/components/chip/snice-chip.types.d.ts +14 -0
- package/dist/components/date-picker/snice-date-picker.d.ts +82 -0
- package/dist/components/date-picker/snice-date-picker.js +847 -0
- package/dist/components/date-picker/snice-date-picker.js.map +1 -0
- package/dist/components/date-picker/snice-date-picker.types.d.ts +71 -0
- package/dist/components/divider/snice-divider.d.ts +17 -0
- package/dist/components/divider/snice-divider.js +122 -0
- package/dist/components/divider/snice-divider.js.map +1 -0
- package/{components/divider/snice-divider.types.ts → dist/components/divider/snice-divider.types.d.ts} +9 -10
- package/dist/components/drawer/snice-drawer.d.ts +37 -0
- package/dist/components/drawer/snice-drawer.js +337 -0
- package/dist/components/drawer/snice-drawer.js.map +1 -0
- package/dist/components/drawer/snice-drawer.types.d.ts +16 -0
- package/dist/components/input/snice-input.d.ts +65 -0
- package/dist/components/input/snice-input.js +567 -0
- package/dist/components/input/snice-input.js.map +1 -0
- package/dist/components/input/snice-input.types.d.ts +53 -0
- package/dist/components/layout/snice-layout-blog.d.ts +4 -0
- package/dist/components/layout/snice-layout-blog.js +67 -0
- package/dist/components/layout/snice-layout-blog.js.map +1 -0
- package/dist/components/layout/snice-layout-card.d.ts +6 -0
- package/dist/components/layout/snice-layout-card.js +64 -0
- package/dist/components/layout/snice-layout-card.js.map +1 -0
- package/dist/components/layout/snice-layout-centered.d.ts +5 -0
- package/dist/components/layout/snice-layout-centered.js +48 -0
- package/dist/components/layout/snice-layout-centered.js.map +1 -0
- package/dist/components/layout/snice-layout-dashboard.d.ts +4 -0
- package/dist/components/layout/snice-layout-dashboard.js +64 -0
- package/dist/components/layout/snice-layout-dashboard.js.map +1 -0
- package/dist/components/layout/snice-layout-fullscreen.d.ts +5 -0
- package/dist/components/layout/snice-layout-fullscreen.js +60 -0
- package/dist/components/layout/snice-layout-fullscreen.js.map +1 -0
- package/dist/components/layout/snice-layout-landing.d.ts +4 -0
- package/dist/components/layout/snice-layout-landing.js +66 -0
- package/dist/components/layout/snice-layout-landing.js.map +1 -0
- package/dist/components/layout/snice-layout-minimal.d.ts +4 -0
- package/dist/components/layout/snice-layout-minimal.js +38 -0
- package/dist/components/layout/snice-layout-minimal.js.map +1 -0
- package/dist/components/layout/snice-layout-sidebar.d.ts +5 -0
- package/dist/components/layout/snice-layout-sidebar.js +74 -0
- package/dist/components/layout/snice-layout-sidebar.js.map +1 -0
- package/dist/components/layout/snice-layout-split.d.ts +6 -0
- package/dist/components/layout/snice-layout-split.js +58 -0
- package/dist/components/layout/snice-layout-split.js.map +1 -0
- package/dist/components/layout/snice-layout.d.ts +4 -0
- package/dist/components/layout/snice-layout.js +54 -0
- package/dist/components/layout/snice-layout.js.map +1 -0
- package/{components/layout/snice-layout.types.ts → dist/components/layout/snice-layout.types.d.ts} +1 -3
- package/dist/components/login/snice-login.d.ts +44 -0
- package/dist/components/login/snice-login.js +382 -0
- package/dist/components/login/snice-login.js.map +1 -0
- package/dist/components/login/snice-login.types.d.ts +26 -0
- package/dist/components/modal/snice-modal.d.ts +32 -0
- package/dist/components/modal/snice-modal.js +280 -0
- package/dist/components/modal/snice-modal.js.map +1 -0
- package/dist/components/modal/snice-modal.types.d.ts +18 -0
- package/dist/components/pagination/snice-pagination.d.ts +26 -0
- package/dist/components/pagination/snice-pagination.js +373 -0
- package/dist/components/pagination/snice-pagination.js.map +1 -0
- package/dist/components/pagination/snice-pagination.types.d.ts +18 -0
- package/dist/components/progress/snice-progress.d.ts +35 -0
- package/dist/components/progress/snice-progress.js +305 -0
- package/dist/components/progress/snice-progress.js.map +1 -0
- package/dist/components/progress/snice-progress.types.d.ts +18 -0
- package/dist/components/radio/snice-radio.d.ts +33 -0
- package/dist/components/radio/snice-radio.js +279 -0
- package/dist/components/radio/snice-radio.js.map +1 -0
- package/dist/components/radio/snice-radio.types.d.ts +19 -0
- package/dist/components/select/snice-option.d.ts +17 -0
- package/dist/components/select/snice-option.js +88 -0
- package/dist/components/select/snice-option.js.map +1 -0
- package/{components/select/snice-option.types.ts → dist/components/select/snice-option.types.d.ts} +8 -8
- package/dist/components/select/snice-select.d.ts +89 -0
- package/dist/components/select/snice-select.js +864 -0
- package/dist/components/select/snice-select.js.map +1 -0
- package/dist/components/select/snice-select.types.d.ts +49 -0
- package/dist/components/skeleton/snice-skeleton.d.ts +16 -0
- package/dist/components/skeleton/snice-skeleton.js +166 -0
- package/dist/components/skeleton/snice-skeleton.js.map +1 -0
- package/{components/skeleton/snice-skeleton.types.ts → dist/components/skeleton/snice-skeleton.types.d.ts} +7 -8
- package/dist/components/snice-cell-C8aBfN72.js +4 -0
- package/dist/components/snice-cell-C8aBfN72.js.map +1 -0
- package/dist/components/switch/snice-switch.d.ts +38 -0
- package/dist/components/switch/snice-switch.js +305 -0
- package/dist/components/switch/snice-switch.js.map +1 -0
- package/dist/components/switch/snice-switch.types.d.ts +21 -0
- package/dist/components/symbols.d.ts +1 -0
- package/dist/components/symbols.js +22 -0
- package/dist/components/symbols.js.map +1 -0
- package/dist/components/table/snice-cell-boolean.d.ts +21 -0
- package/dist/components/table/snice-cell-boolean.js +164 -0
- package/dist/components/table/snice-cell-boolean.js.map +1 -0
- package/dist/components/table/snice-cell-date.d.ts +24 -0
- package/dist/components/table/snice-cell-date.js +253 -0
- package/dist/components/table/snice-cell-date.js.map +1 -0
- package/dist/components/table/snice-cell-duration.d.ts +16 -0
- package/dist/components/table/snice-cell-duration.js +130 -0
- package/dist/components/table/snice-cell-duration.js.map +1 -0
- package/dist/components/table/snice-cell-filesize.d.ts +16 -0
- package/dist/components/table/snice-cell-filesize.js +126 -0
- package/dist/components/table/snice-cell-filesize.js.map +1 -0
- package/dist/components/table/snice-cell-number.d.ts +23 -0
- package/dist/components/table/snice-cell-number.js +215 -0
- package/dist/components/table/snice-cell-number.js.map +1 -0
- package/dist/components/table/snice-cell-progress.d.ts +17 -0
- package/dist/components/table/snice-cell-progress.js +121 -0
- package/dist/components/table/snice-cell-progress.js.map +1 -0
- package/dist/components/table/snice-cell-rating.d.ts +17 -0
- package/dist/components/table/snice-cell-rating.js +120 -0
- package/dist/components/table/snice-cell-rating.js.map +1 -0
- package/dist/components/table/snice-cell-sparkline.d.ts +29 -0
- package/dist/components/table/snice-cell-sparkline.js +306 -0
- package/dist/components/table/snice-cell-sparkline.js.map +1 -0
- package/dist/components/table/snice-cell-text.d.ts +19 -0
- package/dist/components/table/snice-cell-text.js +161 -0
- package/dist/components/table/snice-cell-text.js.map +1 -0
- package/dist/components/table/snice-cell.d.ts +32 -0
- package/dist/components/table/snice-cell.js +458 -0
- package/dist/components/table/snice-cell.js.map +1 -0
- package/dist/components/table/snice-column.d.ts +62 -0
- package/dist/components/table/snice-column.js +506 -0
- package/dist/components/table/snice-column.js.map +1 -0
- package/dist/components/table/snice-header.d.ts +33 -0
- package/dist/components/table/snice-header.js +289 -0
- package/dist/components/table/snice-header.js.map +1 -0
- package/dist/components/table/snice-progress.d.ts +10 -0
- package/dist/components/table/snice-progress.js +105 -0
- package/dist/components/table/snice-progress.js.map +1 -0
- package/dist/components/table/snice-rating.d.ts +9 -0
- package/dist/components/table/snice-rating.js +81 -0
- package/dist/components/table/snice-rating.js.map +1 -0
- package/dist/components/table/snice-row.d.ts +43 -0
- package/dist/components/table/snice-row.js +353 -0
- package/dist/components/table/snice-row.js.map +1 -0
- package/dist/components/table/snice-table.d.ts +69 -0
- package/dist/components/table/snice-table.js +792 -0
- package/dist/components/table/snice-table.js.map +1 -0
- package/dist/components/table/snice-table.types.d.ts +137 -0
- package/dist/components/tabs/snice-tab-panel.d.ts +12 -0
- package/dist/components/tabs/snice-tab-panel.js +87 -0
- package/dist/components/tabs/snice-tab-panel.js.map +1 -0
- package/dist/components/tabs/snice-tab.d.ts +13 -0
- package/dist/components/tabs/snice-tab.js +98 -0
- package/dist/components/tabs/snice-tab.js.map +1 -0
- package/dist/components/tabs/snice-tabs.d.ts +34 -0
- package/dist/components/tabs/snice-tabs.js +375 -0
- package/dist/components/tabs/snice-tabs.js.map +1 -0
- package/dist/components/tabs/snice-tabs.types.d.ts +23 -0
- package/dist/components/toast/snice-toast-container.d.ts +25 -0
- package/dist/components/toast/snice-toast-container.js +252 -0
- package/dist/components/toast/snice-toast-container.js.map +1 -0
- package/dist/components/toast/snice-toast.d.ts +23 -0
- package/dist/components/toast/snice-toast.js +321 -0
- package/dist/components/toast/snice-toast.js.map +1 -0
- package/dist/components/toast/snice-toast.types.d.ts +30 -0
- package/dist/components/tooltip/snice-tooltip.d.ts +50 -0
- package/dist/components/tooltip/snice-tooltip.js +644 -0
- package/dist/components/tooltip/snice-tooltip.js.map +1 -0
- package/dist/components/tooltip/snice-tooltip.types.d.ts +18 -0
- package/dist/components/transitions.d.ts +11 -0
- package/dist/components/transitions.js +72 -0
- package/dist/components/transitions.js.map +1 -0
- package/dist/index.cjs +16 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.cjs.min.map +1 -1
- package/dist/index.esm.js +16 -20
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +3 -3
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +16 -20
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +3 -3
- package/dist/index.iife.min.js.map +1 -1
- package/dist/symbols.esm.js +1 -1
- package/dist/transitions.esm.js +1 -1
- package/package.json +10 -6
- package/components/accordion/demo.html +0 -403
- package/components/accordion/snice-accordion-item.css +0 -85
- package/components/accordion/snice-accordion-item.ts +0 -226
- package/components/accordion/snice-accordion.css +0 -31
- package/components/accordion/snice-accordion.ts +0 -182
- package/components/accordion/snice-accordion.types.ts +0 -32
- package/components/alert/demo.html +0 -445
- package/components/alert/snice-alert.css +0 -195
- package/components/alert/snice-alert.ts +0 -141
- package/components/avatar/demo.html +0 -598
- package/components/avatar/snice-avatar.css +0 -131
- package/components/avatar/snice-avatar.ts +0 -136
- package/components/avatar/snice-avatar.types.ts +0 -13
- package/components/badge/demo.html +0 -523
- package/components/badge/snice-badge.css +0 -161
- package/components/badge/snice-badge.ts +0 -117
- package/components/breadcrumbs/demo.html +0 -404
- package/components/breadcrumbs/snice-breadcrumbs.css +0 -133
- package/components/breadcrumbs/snice-breadcrumbs.ts +0 -191
- package/components/breadcrumbs/snice-breadcrumbs.types.ts +0 -26
- package/components/breadcrumbs/snice-crumb.ts +0 -26
- package/components/button/demo.html +0 -42
- package/components/button/snice-button.css +0 -230
- package/components/button/snice-button.ts +0 -169
- package/components/button/snice-button.types.ts +0 -25
- package/components/card/demo.html +0 -525
- package/components/card/snice-card.css +0 -140
- package/components/card/snice-card.ts +0 -102
- package/components/checkbox/demo.html +0 -253
- package/components/checkbox/snice-checkbox.css +0 -164
- package/components/checkbox/snice-checkbox.ts +0 -223
- package/components/checkbox/snice-checkbox.types.ts +0 -22
- package/components/chip/demo.html +0 -383
- package/components/chip/snice-chip.css +0 -195
- package/components/chip/snice-chip.ts +0 -139
- package/components/chip/snice-chip.types.ts +0 -15
- package/components/date-picker/README.md +0 -233
- package/components/date-picker/demo.html +0 -191
- package/components/date-picker/snice-date-picker.css +0 -330
- package/components/date-picker/snice-date-picker.ts +0 -777
- package/components/date-picker/snice-date-picker.types.ts +0 -83
- package/components/divider/demo.html +0 -233
- package/components/divider/snice-divider.css +0 -155
- package/components/divider/snice-divider.ts +0 -69
- package/components/drawer/demo.html +0 -328
- package/components/drawer/snice-drawer.css +0 -476
- package/components/drawer/snice-drawer.ts +0 -287
- package/components/drawer/snice-drawer.types.ts +0 -17
- package/components/global.d.ts +0 -14
- package/components/input/demo.html +0 -303
- package/components/input/snice-input.css +0 -257
- package/components/input/snice-input.ts +0 -442
- package/components/input/snice-input.types.ts +0 -59
- package/components/input/test.html +0 -77
- package/components/layout/README.md +0 -260
- package/components/layout/demo.html +0 -538
- package/components/layout/snice-layout-blog.css +0 -129
- package/components/layout/snice-layout-blog.ts +0 -48
- package/components/layout/snice-layout-card.css +0 -104
- package/components/layout/snice-layout-card.ts +0 -35
- package/components/layout/snice-layout-centered.css +0 -51
- package/components/layout/snice-layout-centered.ts +0 -22
- package/components/layout/snice-layout-dashboard.css +0 -98
- package/components/layout/snice-layout-dashboard.ts +0 -45
- package/components/layout/snice-layout-fullscreen.css +0 -72
- package/components/layout/snice-layout-fullscreen.ts +0 -34
- package/components/layout/snice-layout-landing.css +0 -92
- package/components/layout/snice-layout-landing.ts +0 -47
- package/components/layout/snice-layout-minimal.css +0 -16
- package/components/layout/snice-layout-minimal.ts +0 -19
- package/components/layout/snice-layout-sidebar.css +0 -117
- package/components/layout/snice-layout-sidebar.ts +0 -48
- package/components/layout/snice-layout-split.css +0 -103
- package/components/layout/snice-layout-split.ts +0 -29
- package/components/layout/snice-layout.css +0 -72
- package/components/layout/snice-layout.ts +0 -35
- package/components/login/demo-auth-controller.ts +0 -185
- package/components/login/demo.html +0 -470
- package/components/login/snice-login.css +0 -204
- package/components/login/snice-login.ts +0 -326
- package/components/login/snice-login.types.ts +0 -29
- package/components/modal/demo.html +0 -291
- package/components/modal/snice-modal.css +0 -203
- package/components/modal/snice-modal.ts +0 -233
- package/components/modal/snice-modal.types.ts +0 -21
- package/components/pagination/demo.html +0 -395
- package/components/pagination/snice-pagination.ts +0 -333
- package/components/pagination/snice-pagination.types.ts +0 -21
- package/components/progress/demo.html +0 -510
- package/components/progress/snice-progress.css +0 -267
- package/components/progress/snice-progress.ts +0 -247
- package/components/progress/snice-progress.types.ts +0 -19
- package/components/radio/demo.html +0 -287
- package/components/radio/snice-radio.css +0 -171
- package/components/radio/snice-radio.ts +0 -218
- package/components/radio/snice-radio.types.ts +0 -21
- package/components/select/demo.html +0 -511
- package/components/select/snice-option.ts +0 -52
- package/components/select/snice-select.css +0 -392
- package/components/select/snice-select.ts +0 -796
- package/components/select/snice-select.types.ts +0 -55
- package/components/skeleton/demo.html +0 -514
- package/components/skeleton/snice-skeleton.css +0 -109
- package/components/skeleton/snice-skeleton.ts +0 -126
- package/components/switch/demo.html +0 -284
- package/components/switch/snice-switch.css +0 -221
- package/components/switch/snice-switch.ts +0 -229
- package/components/switch/snice-switch.types.ts +0 -23
- package/components/symbols.ts +0 -23
- package/components/table/demo-table-controller.ts +0 -100
- package/components/table/demo.html +0 -480
- package/components/table/snice-cell-boolean.ts +0 -112
- package/components/table/snice-cell-date.ts +0 -210
- package/components/table/snice-cell-duration.ts +0 -91
- package/components/table/snice-cell-filesize.ts +0 -90
- package/components/table/snice-cell-number.ts +0 -165
- package/components/table/snice-cell-progress.ts +0 -83
- package/components/table/snice-cell-rating.ts +0 -82
- package/components/table/snice-cell-sparkline.ts +0 -253
- package/components/table/snice-cell-text.ts +0 -125
- package/components/table/snice-cell.css +0 -296
- package/components/table/snice-cell.ts +0 -473
- package/components/table/snice-column.ts +0 -353
- package/components/table/snice-header.css +0 -243
- package/components/table/snice-header.ts +0 -261
- package/components/table/snice-progress.ts +0 -66
- package/components/table/snice-rating.ts +0 -45
- package/components/table/snice-row.css +0 -255
- package/components/table/snice-row.ts +0 -331
- package/components/table/snice-table.css +0 -241
- package/components/table/snice-table.ts +0 -737
- package/components/table/snice-table.types.ts +0 -158
- package/components/tabs/demo.html +0 -487
- package/components/tabs/snice-tab-panel.css +0 -264
- package/components/tabs/snice-tab-panel.ts +0 -47
- package/components/tabs/snice-tab.css +0 -96
- package/components/tabs/snice-tab.ts +0 -65
- package/components/tabs/snice-tabs.css +0 -189
- package/components/tabs/snice-tabs.ts +0 -332
- package/components/tabs/snice-tabs.types.ts +0 -28
- package/components/theme/theme.css +0 -234
- package/components/toast/demo.html +0 -329
- package/components/toast/snice-toast-container.ts +0 -256
- package/components/toast/snice-toast.css +0 -213
- package/components/toast/snice-toast.ts +0 -276
- package/components/toast/snice-toast.types.ts +0 -35
- package/components/tooltip/demo.html +0 -350
- package/components/tooltip/snice-tooltip-portal.css +0 -79
- package/components/tooltip/snice-tooltip.css +0 -117
- package/components/tooltip/snice-tooltip.ts +0 -612
- package/components/tooltip/snice-tooltip.types.ts +0 -32
- package/components/transitions.ts +0 -94
- package/components/tsconfig.json +0 -18
|
@@ -1,796 +0,0 @@
|
|
|
1
|
-
import { element, property, query, queryAll, on, watch, dispatch, ready, dispose } from 'snice';
|
|
2
|
-
import css from './snice-select.css?inline';
|
|
3
|
-
import type { SelectSize, SelectOption, SniceSelectElement } from './snice-select.types';
|
|
4
|
-
import './snice-option';
|
|
5
|
-
|
|
6
|
-
@element('snice-select')
|
|
7
|
-
export class SniceSelect extends HTMLElement implements SniceSelectElement {
|
|
8
|
-
@property({ type: Boolean, reflect: true })
|
|
9
|
-
disabled = false;
|
|
10
|
-
|
|
11
|
-
@property({ type: Boolean, reflect: true })
|
|
12
|
-
required = false;
|
|
13
|
-
|
|
14
|
-
@property({ type: Boolean, reflect: true })
|
|
15
|
-
invalid = false;
|
|
16
|
-
|
|
17
|
-
@property({ type: Boolean, reflect: true })
|
|
18
|
-
readonly = false;
|
|
19
|
-
|
|
20
|
-
@property({ type: Boolean, reflect: true })
|
|
21
|
-
multiple = false;
|
|
22
|
-
|
|
23
|
-
@property({ type: Boolean, reflect: true })
|
|
24
|
-
searchable = false;
|
|
25
|
-
|
|
26
|
-
@property({ type: Boolean, reflect: true })
|
|
27
|
-
clearable = false;
|
|
28
|
-
|
|
29
|
-
@property({ type: Boolean, reflect: true })
|
|
30
|
-
open = false;
|
|
31
|
-
|
|
32
|
-
@property({ reflect: true })
|
|
33
|
-
size: SelectSize = 'medium';
|
|
34
|
-
|
|
35
|
-
@property({ reflect: true })
|
|
36
|
-
name = '';
|
|
37
|
-
|
|
38
|
-
@property({ reflect: true })
|
|
39
|
-
value = '';
|
|
40
|
-
|
|
41
|
-
@property({ reflect: true })
|
|
42
|
-
label = '';
|
|
43
|
-
|
|
44
|
-
@property({ reflect: true })
|
|
45
|
-
placeholder = 'Select an option';
|
|
46
|
-
|
|
47
|
-
@property({ reflect: true, attribute: 'max-height' })
|
|
48
|
-
maxHeight = '200px';
|
|
49
|
-
|
|
50
|
-
// Options will be read from child snice-option elements
|
|
51
|
-
private options: SelectOption[] = [];
|
|
52
|
-
|
|
53
|
-
@query('.select-trigger')
|
|
54
|
-
trigger?: HTMLButtonElement;
|
|
55
|
-
|
|
56
|
-
@query('.select-dropdown')
|
|
57
|
-
dropdown?: HTMLElement;
|
|
58
|
-
|
|
59
|
-
@query('.select-value')
|
|
60
|
-
valueDisplay?: HTMLElement;
|
|
61
|
-
|
|
62
|
-
@query('.select-label')
|
|
63
|
-
labelElement?: HTMLElement;
|
|
64
|
-
|
|
65
|
-
@query('.select-search-input')
|
|
66
|
-
searchInput?: HTMLInputElement;
|
|
67
|
-
|
|
68
|
-
@query('.select-options')
|
|
69
|
-
optionsList?: HTMLElement;
|
|
70
|
-
|
|
71
|
-
@query('.select-native')
|
|
72
|
-
nativeSelect?: HTMLSelectElement;
|
|
73
|
-
|
|
74
|
-
@query('.select-clear')
|
|
75
|
-
clearButton?: HTMLElement;
|
|
76
|
-
|
|
77
|
-
@query('.select-arrow')
|
|
78
|
-
arrow?: HTMLElement;
|
|
79
|
-
|
|
80
|
-
@query('.select-search')
|
|
81
|
-
searchContainer?: HTMLElement;
|
|
82
|
-
|
|
83
|
-
@queryAll('.select-option')
|
|
84
|
-
optionElements?: HTMLElement[];
|
|
85
|
-
|
|
86
|
-
private filteredOptions: SelectOption[] = [];
|
|
87
|
-
private selectedValues: Set<string> = new Set();
|
|
88
|
-
private focusedIndex = -1;
|
|
89
|
-
|
|
90
|
-
html() {
|
|
91
|
-
// Initial render - options will be populated in @ready()
|
|
92
|
-
return /*html*/`
|
|
93
|
-
<div class="select-wrapper">
|
|
94
|
-
<label class="select-label select-label--${this.size} ${this.required ? 'select-label--required' : ''}" part="label" ${!this.label ? 'hidden' : ''}>
|
|
95
|
-
${this.label}
|
|
96
|
-
</label>
|
|
97
|
-
|
|
98
|
-
<button
|
|
99
|
-
type="button"
|
|
100
|
-
class="select-trigger select-trigger--${this.size}"
|
|
101
|
-
aria-haspopup="listbox"
|
|
102
|
-
aria-expanded="false"
|
|
103
|
-
aria-label="${this.label || 'Select'}"
|
|
104
|
-
part="trigger">
|
|
105
|
-
|
|
106
|
-
<div class="select-value" part="value">
|
|
107
|
-
<span class="select-placeholder">${this.placeholder}</span>
|
|
108
|
-
</div>
|
|
109
|
-
|
|
110
|
-
<span class="select-icons">
|
|
111
|
-
<span class="select-clear" aria-label="Clear selection" style="display: none;">
|
|
112
|
-
<svg width="14" height="14" viewBox="0 0 14 14" fill="currentColor">
|
|
113
|
-
<path d="M14 1.41L12.59 0L7 5.59L1.41 0L0 1.41L5.59 7L0 12.59L1.41 14L7 8.41L12.59 14L14 12.59L8.41 7L14 1.41Z"/>
|
|
114
|
-
</svg>
|
|
115
|
-
</span>
|
|
116
|
-
<span class="select-arrow">
|
|
117
|
-
<svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor">
|
|
118
|
-
<path d="M6 9L1 4h10L6 9z"/>
|
|
119
|
-
</svg>
|
|
120
|
-
</span>
|
|
121
|
-
</span>
|
|
122
|
-
</button>
|
|
123
|
-
|
|
124
|
-
<div class="select-dropdown"
|
|
125
|
-
role="listbox"
|
|
126
|
-
aria-label="${this.label || 'Options'}"
|
|
127
|
-
part="dropdown">
|
|
128
|
-
|
|
129
|
-
<div class="select-search" part="search" ${!this.searchable ? 'hidden' : ''}>
|
|
130
|
-
<input
|
|
131
|
-
type="text"
|
|
132
|
-
class="select-search-input"
|
|
133
|
-
placeholder="Search..."
|
|
134
|
-
aria-label="Search options"
|
|
135
|
-
part="search-input" />
|
|
136
|
-
</div>
|
|
137
|
-
|
|
138
|
-
<div class="select-options" part="options">
|
|
139
|
-
<!-- Options will be rendered in @ready() -->
|
|
140
|
-
</div>
|
|
141
|
-
</div>
|
|
142
|
-
|
|
143
|
-
<!-- Hidden native select for form submission -->
|
|
144
|
-
<select
|
|
145
|
-
class="select-native"
|
|
146
|
-
name="${this.name || ''}"
|
|
147
|
-
tabindex="-1"
|
|
148
|
-
aria-hidden="true">
|
|
149
|
-
<!-- Options will be added in @ready() -->
|
|
150
|
-
</select>
|
|
151
|
-
</div>
|
|
152
|
-
`;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
private renderOptions(): string {
|
|
156
|
-
const options = this.searchable ? this.filteredOptions : this.options;
|
|
157
|
-
|
|
158
|
-
if (options.length === 0) {
|
|
159
|
-
return /*html*/`
|
|
160
|
-
<div class="select-no-options">
|
|
161
|
-
<span class="select-no-options-text" data-search="true" ${!this.searchable || this.filteredOptions.length > 0 ? 'hidden' : ''}>No matches found</span>
|
|
162
|
-
<span class="select-no-options-text" data-search="false" ${this.searchable && this.filteredOptions.length === 0 ? 'hidden' : ''}>No options available</span>
|
|
163
|
-
</div>
|
|
164
|
-
`;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return options.map((opt, index) => {
|
|
168
|
-
const isSelected = this.multiple ?
|
|
169
|
-
this.selectedValues.has(opt.value) :
|
|
170
|
-
opt.value === this.value;
|
|
171
|
-
|
|
172
|
-
return /*html*/`
|
|
173
|
-
<div class="select-option
|
|
174
|
-
${isSelected ? 'select-option--selected' : ''}
|
|
175
|
-
${opt.disabled ? 'select-option--disabled' : ''}
|
|
176
|
-
${index === this.focusedIndex ? 'select-option--focused' : ''}
|
|
177
|
-
${opt.icon ? 'select-option--has-icon' : ''}"
|
|
178
|
-
data-value="${opt.value}"
|
|
179
|
-
role="option"
|
|
180
|
-
aria-selected="${isSelected}"
|
|
181
|
-
aria-disabled="${opt.disabled}"
|
|
182
|
-
part="option">
|
|
183
|
-
<span class="select-option-check" ${!this.multiple ? 'hidden' : ''}>
|
|
184
|
-
<span class="select-option-check-mark" ${!isSelected ? 'hidden' : ''}>✓</span>
|
|
185
|
-
</span>
|
|
186
|
-
<img class="select-option-icon" src="${opt.icon || ''}" alt="" ${!opt.icon ? 'hidden' : ''} />
|
|
187
|
-
<span class="select-option-label">${opt.label}</span>
|
|
188
|
-
</div>
|
|
189
|
-
`;
|
|
190
|
-
}).join('');
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
css() {
|
|
194
|
-
return css;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
@ready()
|
|
198
|
-
init() {
|
|
199
|
-
// Read options from child snice-option elements
|
|
200
|
-
this.readOptionsFromChildren();
|
|
201
|
-
|
|
202
|
-
// Initialize selected values
|
|
203
|
-
if (this.multiple && this.value) {
|
|
204
|
-
this.selectedValues = new Set(this.value.split(',').map(v => v.trim()));
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Initialize filtered options
|
|
208
|
-
this.filteredOptions = [...this.options];
|
|
209
|
-
|
|
210
|
-
// Set initial imperative state
|
|
211
|
-
this.updateTriggerState();
|
|
212
|
-
this.updateDropdownState();
|
|
213
|
-
this.updateNativeSelectAttributes();
|
|
214
|
-
|
|
215
|
-
// Now that we have options, update everything
|
|
216
|
-
this.updateDropdownContent();
|
|
217
|
-
this.updateNativeSelect();
|
|
218
|
-
this.updateValueDisplay();
|
|
219
|
-
this.updateClearButton();
|
|
220
|
-
|
|
221
|
-
// Watch for changes to child options
|
|
222
|
-
this.observeChildren();
|
|
223
|
-
|
|
224
|
-
// Setup global event listeners
|
|
225
|
-
this.setupGlobalListeners();
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
@dispose()
|
|
229
|
-
cleanup() {
|
|
230
|
-
this.removeGlobalListeners();
|
|
231
|
-
this.childObserver?.disconnect();
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
private outsideClickHandler?: (e: MouseEvent) => void;
|
|
235
|
-
private globalKeyHandler?: (e: KeyboardEvent) => void;
|
|
236
|
-
|
|
237
|
-
private setupGlobalListeners() {
|
|
238
|
-
// Create bound handlers
|
|
239
|
-
this.outsideClickHandler = (e: MouseEvent) => {
|
|
240
|
-
if (!this.contains(e.target as Node) && this.open) {
|
|
241
|
-
this.closeDropdown();
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
this.globalKeyHandler = (e: KeyboardEvent) => {
|
|
246
|
-
if (!this.open) return;
|
|
247
|
-
|
|
248
|
-
switch (e.key) {
|
|
249
|
-
case 'Escape':
|
|
250
|
-
this.closeDropdown();
|
|
251
|
-
this.trigger?.focus();
|
|
252
|
-
break;
|
|
253
|
-
case 'ArrowDown':
|
|
254
|
-
e.preventDefault();
|
|
255
|
-
this.focusNextOption();
|
|
256
|
-
break;
|
|
257
|
-
case 'ArrowUp':
|
|
258
|
-
e.preventDefault();
|
|
259
|
-
this.focusPreviousOption();
|
|
260
|
-
break;
|
|
261
|
-
case 'Enter':
|
|
262
|
-
case ' ':
|
|
263
|
-
e.preventDefault();
|
|
264
|
-
if (this.focusedIndex >= 0) {
|
|
265
|
-
const options = this.searchable ? this.filteredOptions : this.options;
|
|
266
|
-
const option = options[this.focusedIndex];
|
|
267
|
-
if (option && !option.disabled) {
|
|
268
|
-
this.handleOptionSelect(option);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
break;
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
// Add listeners
|
|
276
|
-
document.addEventListener('click', this.outsideClickHandler);
|
|
277
|
-
document.addEventListener('keydown', this.globalKeyHandler);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
private removeGlobalListeners() {
|
|
281
|
-
if (this.outsideClickHandler) {
|
|
282
|
-
document.removeEventListener('click', this.outsideClickHandler);
|
|
283
|
-
}
|
|
284
|
-
if (this.globalKeyHandler) {
|
|
285
|
-
document.removeEventListener('keydown', this.globalKeyHandler);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// Manual observation of light DOM children (snice-option elements)
|
|
290
|
-
private observeChildren() {
|
|
291
|
-
const observer = new MutationObserver((mutations) => {
|
|
292
|
-
this.handleChildrenChange(mutations);
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
// Observe the host element (this) for changes to its light DOM children
|
|
296
|
-
observer.observe(this, {
|
|
297
|
-
childList: true,
|
|
298
|
-
subtree: true,
|
|
299
|
-
attributes: true,
|
|
300
|
-
attributeFilter: ['value', 'label', 'disabled', 'selected']
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
// Store for cleanup
|
|
304
|
-
this.childObserver = observer;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
private childObserver?: MutationObserver;
|
|
308
|
-
|
|
309
|
-
private handleChildrenChange(mutations: MutationRecord[]) {
|
|
310
|
-
// Check if any of the mutations are relevant (snice-option elements or their attributes)
|
|
311
|
-
const relevant = mutations.some(m => {
|
|
312
|
-
if (m.type === 'childList') return true;
|
|
313
|
-
if (m.type === 'attributes' && ['value', 'label', 'disabled', 'selected'].includes(m.attributeName!)) {
|
|
314
|
-
return m.target.nodeName === 'SNICE-OPTION';
|
|
315
|
-
}
|
|
316
|
-
return false;
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
if (relevant) {
|
|
320
|
-
this.readOptionsFromChildren();
|
|
321
|
-
this.filteredOptions = [...this.options];
|
|
322
|
-
this.updateNativeSelect();
|
|
323
|
-
this.updateValueDisplay();
|
|
324
|
-
this.updateClearButton();
|
|
325
|
-
this.updateDropdownContent();
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
private readOptionsFromChildren() {
|
|
331
|
-
// Get all snice-option children from light DOM
|
|
332
|
-
const optionElements = Array.from(this.querySelectorAll('snice-option'));
|
|
333
|
-
|
|
334
|
-
this.options = optionElements.map(opt => {
|
|
335
|
-
const sniceOption = opt as any;
|
|
336
|
-
// Use the optionData getter if available, otherwise construct from properties
|
|
337
|
-
if (sniceOption.optionData) {
|
|
338
|
-
return sniceOption.optionData;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
return {
|
|
342
|
-
value: opt.getAttribute('value') || '',
|
|
343
|
-
label: opt.getAttribute('label') || opt.textContent?.trim() || '',
|
|
344
|
-
disabled: opt.hasAttribute('disabled'),
|
|
345
|
-
selected: opt.hasAttribute('selected')
|
|
346
|
-
};
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
@on(['keydown:Enter', 'keydown:Space', 'keydown:ArrowDown', 'keydown:ArrowUp'], '.select-trigger')
|
|
351
|
-
handleTriggerOpen(e: KeyboardEvent) {
|
|
352
|
-
e.preventDefault();
|
|
353
|
-
if (!this.open) {
|
|
354
|
-
this.openDropdown();
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
@on('keydown:Escape', '.select-search-input')
|
|
359
|
-
handleSearchEscape() {
|
|
360
|
-
this.closeDropdown();
|
|
361
|
-
this.trigger?.focus();
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
@on('keydown:ArrowDown', '.select-search-input')
|
|
365
|
-
handleSearchArrowDown(e: KeyboardEvent) {
|
|
366
|
-
e.preventDefault();
|
|
367
|
-
this.focusNextOption();
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
@on('keydown:ArrowUp', '.select-search-input')
|
|
371
|
-
handleSearchArrowUp(e: KeyboardEvent) {
|
|
372
|
-
e.preventDefault();
|
|
373
|
-
this.focusPreviousOption();
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
@on('keydown:Enter', '.select-search-input')
|
|
377
|
-
handleSearchEnter(e: KeyboardEvent) {
|
|
378
|
-
e.preventDefault();
|
|
379
|
-
if (this.focusedIndex >= 0) {
|
|
380
|
-
const options = this.searchable ? this.filteredOptions : this.options;
|
|
381
|
-
const option = options[this.focusedIndex];
|
|
382
|
-
if (option && !option.disabled) {
|
|
383
|
-
this.handleOptionSelect(option);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
private focusNextOption() {
|
|
389
|
-
const options = this.searchable ? this.filteredOptions : this.options;
|
|
390
|
-
const enabledOptions = options.filter(opt => !opt.disabled);
|
|
391
|
-
if (enabledOptions.length === 0) return;
|
|
392
|
-
|
|
393
|
-
this.focusedIndex++;
|
|
394
|
-
if (this.focusedIndex >= options.length) {
|
|
395
|
-
this.focusedIndex = 0;
|
|
396
|
-
}
|
|
397
|
-
while (options[this.focusedIndex]?.disabled) {
|
|
398
|
-
this.focusedIndex++;
|
|
399
|
-
if (this.focusedIndex >= options.length) {
|
|
400
|
-
this.focusedIndex = 0;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
this.updateOptionFocus();
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
private focusPreviousOption() {
|
|
407
|
-
const options = this.searchable ? this.filteredOptions : this.options;
|
|
408
|
-
const enabledOptions = options.filter(opt => !opt.disabled);
|
|
409
|
-
if (enabledOptions.length === 0) return;
|
|
410
|
-
|
|
411
|
-
this.focusedIndex--;
|
|
412
|
-
if (this.focusedIndex < 0) {
|
|
413
|
-
this.focusedIndex = options.length - 1;
|
|
414
|
-
}
|
|
415
|
-
while (options[this.focusedIndex]?.disabled) {
|
|
416
|
-
this.focusedIndex--;
|
|
417
|
-
if (this.focusedIndex < 0) {
|
|
418
|
-
this.focusedIndex = options.length - 1;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
this.updateOptionFocus();
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
private updateOptionFocus() {
|
|
425
|
-
if (this.optionElements) {
|
|
426
|
-
this.optionElements.forEach((el, index) => {
|
|
427
|
-
el.classList.toggle('select-option--focused', index === this.focusedIndex);
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
@on('click', '.select-trigger')
|
|
433
|
-
handleTriggerClick(e: Event) {
|
|
434
|
-
e.stopPropagation();
|
|
435
|
-
|
|
436
|
-
// Don't toggle if clicking on the clear button or tag remove buttons
|
|
437
|
-
const target = e.target as HTMLElement;
|
|
438
|
-
if (target.closest('.select-clear') || target.closest('.select-tag-remove')) {
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
if (!this.disabled && !this.readonly) {
|
|
443
|
-
this.toggleDropdown();
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
@on('click', '.select-clear', { preventDefault: true, stopPropagation: true })
|
|
448
|
-
handleClearClick(_e: Event) {
|
|
449
|
-
this.clear();
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
@on('click', '.select-tag-remove')
|
|
453
|
-
handleTagRemove(e: Event) {
|
|
454
|
-
e.stopPropagation();
|
|
455
|
-
const target = e.target as HTMLElement;
|
|
456
|
-
const value = target.getAttribute('data-value');
|
|
457
|
-
if (value && this.multiple) {
|
|
458
|
-
this.selectedValues.delete(value);
|
|
459
|
-
this.value = Array.from(this.selectedValues).join(',');
|
|
460
|
-
this.updateNativeSelect();
|
|
461
|
-
this.updateValueDisplay();
|
|
462
|
-
this.updateClearButton();
|
|
463
|
-
this.dispatchChangeEvent();
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
@on('click', '.select-options')
|
|
468
|
-
handleOptionsClick(e: Event) {
|
|
469
|
-
e.stopPropagation();
|
|
470
|
-
|
|
471
|
-
const target = e.target as HTMLElement;
|
|
472
|
-
const optionEl = target.closest('.select-option') as HTMLElement;
|
|
473
|
-
|
|
474
|
-
if (!optionEl) return;
|
|
475
|
-
|
|
476
|
-
const value = optionEl.getAttribute('data-value');
|
|
477
|
-
if (!value) return;
|
|
478
|
-
|
|
479
|
-
const option = this.options.find(opt => opt.value === value);
|
|
480
|
-
if (option && !option.disabled) {
|
|
481
|
-
this.handleOptionSelect(option);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
@on('input', '.select-search-input')
|
|
486
|
-
handleSearchInput(e: Event) {
|
|
487
|
-
const target = e.target as HTMLInputElement;
|
|
488
|
-
const searchTerm = target.value.toLowerCase();
|
|
489
|
-
|
|
490
|
-
if (searchTerm) {
|
|
491
|
-
this.filteredOptions = this.options.filter(opt =>
|
|
492
|
-
opt.label.toLowerCase().includes(searchTerm)
|
|
493
|
-
);
|
|
494
|
-
} else {
|
|
495
|
-
this.filteredOptions = [...this.options];
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
this.focusedIndex = -1;
|
|
499
|
-
this.updateDropdownContent();
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
private handleOptionSelect(option: SelectOption) {
|
|
503
|
-
if (this.multiple) {
|
|
504
|
-
if (this.selectedValues.has(option.value)) {
|
|
505
|
-
this.selectedValues.delete(option.value);
|
|
506
|
-
} else {
|
|
507
|
-
this.selectedValues.add(option.value);
|
|
508
|
-
}
|
|
509
|
-
this.value = Array.from(this.selectedValues).join(',');
|
|
510
|
-
this.updateDropdownContent();
|
|
511
|
-
} else {
|
|
512
|
-
this.value = option.value;
|
|
513
|
-
this.closeDropdown();
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
this.updateNativeSelect();
|
|
517
|
-
this.updateValueDisplay();
|
|
518
|
-
this.updateClearButton();
|
|
519
|
-
this.dispatchChangeEvent(option);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
@watch('value')
|
|
523
|
-
handleValueChange() {
|
|
524
|
-
if (this.multiple) {
|
|
525
|
-
this.selectedValues = new Set(this.value ? this.value.split(',').map(v => v.trim()) : []);
|
|
526
|
-
}
|
|
527
|
-
this.updateNativeSelect();
|
|
528
|
-
this.updateValueDisplay();
|
|
529
|
-
this.updateClearButton();
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
@watch('disabled')
|
|
533
|
-
handleDisabledChange() {
|
|
534
|
-
this.updateTriggerState();
|
|
535
|
-
this.updateNativeSelectAttributes();
|
|
536
|
-
this.updateClearButton();
|
|
537
|
-
if (this.disabled && this.open) {
|
|
538
|
-
this.closeDropdown();
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
@watch('readonly')
|
|
543
|
-
handleReadonlyChange() {
|
|
544
|
-
this.updateTriggerState();
|
|
545
|
-
this.updateClearButton();
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
@watch('invalid')
|
|
549
|
-
handleInvalidChange() {
|
|
550
|
-
this.updateTriggerState();
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
// Remove the @watch('options') since options are now read from children
|
|
554
|
-
|
|
555
|
-
@watch('open')
|
|
556
|
-
handleOpenChange() {
|
|
557
|
-
this.updateDropdownState();
|
|
558
|
-
this.updateTriggerState();
|
|
559
|
-
|
|
560
|
-
if (this.open && this.searchable && this.searchInput) {
|
|
561
|
-
setTimeout(() => this.searchInput?.focus(), 100);
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
if (!this.open) {
|
|
565
|
-
this.focusedIndex = -1;
|
|
566
|
-
if (this.searchInput) {
|
|
567
|
-
this.searchInput.value = '';
|
|
568
|
-
this.filteredOptions = [...this.options];
|
|
569
|
-
this.updateDropdownContent();
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
@watch('label')
|
|
575
|
-
handleLabelChange() {
|
|
576
|
-
if (this.labelElement) {
|
|
577
|
-
this.labelElement.textContent = this.label;
|
|
578
|
-
if (this.label) {
|
|
579
|
-
this.labelElement.removeAttribute('hidden');
|
|
580
|
-
} else {
|
|
581
|
-
this.labelElement.setAttribute('hidden', '');
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
@watch('placeholder')
|
|
587
|
-
handlePlaceholderChange() {
|
|
588
|
-
this.updateValueDisplay();
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
@watch('required')
|
|
592
|
-
handleRequiredChange() {
|
|
593
|
-
if (this.labelElement) {
|
|
594
|
-
this.labelElement.classList.toggle('select-label--required', this.required);
|
|
595
|
-
}
|
|
596
|
-
this.updateNativeSelectAttributes();
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
@watch('multiple')
|
|
600
|
-
handleMultipleChange() {
|
|
601
|
-
this.updateNativeSelectAttributes();
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
@watch('name')
|
|
605
|
-
handleNameChange() {
|
|
606
|
-
this.updateNativeSelectAttributes();
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
@watch('clearable')
|
|
611
|
-
handleClearableChange() {
|
|
612
|
-
this.updateClearButton();
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
@watch('searchable')
|
|
616
|
-
handleSearchableChange() {
|
|
617
|
-
if (this.searchContainer) {
|
|
618
|
-
if (this.searchable) {
|
|
619
|
-
this.searchContainer.removeAttribute('hidden');
|
|
620
|
-
} else {
|
|
621
|
-
this.searchContainer.setAttribute('hidden', '');
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
private updateValueDisplay() {
|
|
627
|
-
if (!this.valueDisplay) return;
|
|
628
|
-
|
|
629
|
-
const selectedOptions = this.options.filter(opt =>
|
|
630
|
-
this.multiple ? this.selectedValues.has(opt.value) : opt.value === this.value
|
|
631
|
-
);
|
|
632
|
-
|
|
633
|
-
if (this.multiple && selectedOptions.length > 0) {
|
|
634
|
-
this.valueDisplay.innerHTML = /*html*/`
|
|
635
|
-
<div class="select-value--multiple">
|
|
636
|
-
${selectedOptions.map(opt => /*html*/`
|
|
637
|
-
<span class="select-tag">
|
|
638
|
-
<img class="select-tag-icon" src="${opt.icon || ''}" alt="" ${!opt.icon ? 'hidden' : ''} />
|
|
639
|
-
${opt.label}
|
|
640
|
-
<span class="select-tag-remove" data-value="${opt.value}" aria-label="Remove ${opt.label}" ${this.disabled || this.readonly ? 'hidden' : ''}>×</span>
|
|
641
|
-
</span>
|
|
642
|
-
`).join('')}
|
|
643
|
-
</div>
|
|
644
|
-
`;
|
|
645
|
-
} else if (selectedOptions.length > 0) {
|
|
646
|
-
const selected = selectedOptions[0];
|
|
647
|
-
this.valueDisplay.innerHTML = /*html*/`
|
|
648
|
-
<div class="select-value--single">
|
|
649
|
-
<img class="select-value-icon" src="${selected.icon || ''}" alt="" ${!selected.icon ? 'hidden' : ''} />
|
|
650
|
-
<span>${selected.label}</span>
|
|
651
|
-
</div>
|
|
652
|
-
`;
|
|
653
|
-
} else {
|
|
654
|
-
this.valueDisplay.innerHTML = /*html*/`<span class="select-placeholder">${this.placeholder}</span>`;
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
private updateClearButton() {
|
|
659
|
-
if (!this.clearButton) return;
|
|
660
|
-
|
|
661
|
-
const selectedOptions = this.options.filter(opt =>
|
|
662
|
-
this.multiple ? this.selectedValues.has(opt.value) : opt.value === this.value
|
|
663
|
-
);
|
|
664
|
-
|
|
665
|
-
const shouldShow = this.clearable && selectedOptions.length > 0 && !this.disabled && !this.readonly;
|
|
666
|
-
this.clearButton.style.display = shouldShow ? '' : 'none';
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
private updateDropdownContent() {
|
|
670
|
-
if (!this.optionsList) return;
|
|
671
|
-
this.optionsList.innerHTML = this.renderOptions();
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
private updateNativeSelect() {
|
|
675
|
-
if (!this.nativeSelect) return;
|
|
676
|
-
|
|
677
|
-
// Clear and rebuild options
|
|
678
|
-
this.nativeSelect.innerHTML = '';
|
|
679
|
-
this.options.forEach(opt => {
|
|
680
|
-
const option = document.createElement('option');
|
|
681
|
-
option.value = opt.value;
|
|
682
|
-
option.textContent = opt.label;
|
|
683
|
-
option.selected = this.multiple ?
|
|
684
|
-
this.selectedValues.has(opt.value) :
|
|
685
|
-
opt.value === this.value;
|
|
686
|
-
this.nativeSelect!.appendChild(option);
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
@dispatch('@snice/select-change', { bubbles: true, composed: true })
|
|
691
|
-
private dispatchChangeEvent(option?: SelectOption) {
|
|
692
|
-
return {
|
|
693
|
-
value: this.multiple ? Array.from(this.selectedValues) : this.value,
|
|
694
|
-
option,
|
|
695
|
-
select: this
|
|
696
|
-
};
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
@dispatch('@snice/select-open', { bubbles: true, composed: true })
|
|
700
|
-
private dispatchOpenEvent() {
|
|
701
|
-
return { select: this };
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
@dispatch('@snice/select-close', { bubbles: true, composed: true })
|
|
705
|
-
private dispatchCloseEvent() {
|
|
706
|
-
return { select: this };
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
// Public API
|
|
710
|
-
focus() {
|
|
711
|
-
this.trigger?.focus();
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
blur() {
|
|
715
|
-
this.trigger?.blur();
|
|
716
|
-
if (this.open) {
|
|
717
|
-
this.closeDropdown();
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
clear() {
|
|
722
|
-
if (this.multiple) {
|
|
723
|
-
this.selectedValues.clear();
|
|
724
|
-
this.value = '';
|
|
725
|
-
} else {
|
|
726
|
-
this.value = '';
|
|
727
|
-
}
|
|
728
|
-
this.updateNativeSelect();
|
|
729
|
-
this.updateValueDisplay();
|
|
730
|
-
this.updateClearButton();
|
|
731
|
-
this.dispatchChangeEvent();
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
openDropdown() {
|
|
735
|
-
if (!this.open && !this.disabled && !this.readonly) {
|
|
736
|
-
this.open = true;
|
|
737
|
-
this.dispatchOpenEvent();
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
closeDropdown() {
|
|
742
|
-
if (this.open) {
|
|
743
|
-
this.open = false;
|
|
744
|
-
this.dispatchCloseEvent();
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
toggleDropdown() {
|
|
749
|
-
if (this.open) {
|
|
750
|
-
this.closeDropdown();
|
|
751
|
-
} else {
|
|
752
|
-
this.openDropdown();
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
selectOption(value: string) {
|
|
757
|
-
const option = this.options.find(opt => opt.value === value);
|
|
758
|
-
if (option && !option.disabled) {
|
|
759
|
-
this.handleOptionSelect(option);
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
private updateTriggerState() {
|
|
764
|
-
if (!this.trigger) return;
|
|
765
|
-
|
|
766
|
-
this.trigger.classList.toggle('select-trigger--open', this.open);
|
|
767
|
-
this.trigger.classList.toggle('select-trigger--disabled', this.disabled);
|
|
768
|
-
this.trigger.classList.toggle('select-trigger--readonly', this.readonly);
|
|
769
|
-
this.trigger.classList.toggle('select-trigger--invalid', this.invalid);
|
|
770
|
-
this.trigger.setAttribute('aria-expanded', String(this.open));
|
|
771
|
-
this.trigger.disabled = this.disabled;
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
private updateDropdownState() {
|
|
775
|
-
if (!this.dropdown) return;
|
|
776
|
-
|
|
777
|
-
this.dropdown.classList.toggle('select-dropdown--open', this.open);
|
|
778
|
-
|
|
779
|
-
if (this.arrow) {
|
|
780
|
-
this.arrow.classList.toggle('select-arrow--open', this.open);
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
private updateNativeSelectAttributes() {
|
|
785
|
-
if (!this.nativeSelect) return;
|
|
786
|
-
|
|
787
|
-
this.nativeSelect.disabled = this.disabled;
|
|
788
|
-
this.nativeSelect.required = this.required;
|
|
789
|
-
this.nativeSelect.multiple = this.multiple;
|
|
790
|
-
if (this.name) {
|
|
791
|
-
this.nativeSelect.name = this.name;
|
|
792
|
-
} else {
|
|
793
|
-
this.nativeSelect.removeAttribute('name');
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
}
|