@ui-sdk/web 0.0.0-stage → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +10 -2
- package/browser/web/accordion.js +1 -0
- package/browser/web/alert-dialog.js +1 -0
- package/browser/web/autocomplete.js +1 -0
- package/browser/web/avatar.js +1 -0
- package/browser/web/button.js +1 -0
- package/browser/web/calendar.js +1 -0
- package/browser/web/carousel.js +1 -0
- package/browser/web/checkbox.js +1 -0
- package/browser/web/chunks/0eRGibL6.js +1 -0
- package/browser/web/chunks/2bIEUO6_.js +1 -0
- package/browser/web/chunks/5A9w2ULz.js +1 -0
- package/browser/web/chunks/5RSyydjV.js +1 -0
- package/browser/web/chunks/9pWTy2wl.js +1 -0
- package/browser/web/chunks/B0f2j6zz.js +1 -0
- package/browser/web/chunks/B1rux6br.js +1 -0
- package/browser/web/chunks/B3-APaNf.js +1 -0
- package/browser/web/chunks/B7EgSgjQ.js +1 -0
- package/browser/web/chunks/B8QcOzJU.js +1 -0
- package/browser/web/chunks/BFueEkwm.js +3 -0
- package/browser/web/chunks/BJj3oS29.js +1 -0
- package/browser/web/chunks/BNSvTCpr.js +1 -0
- package/browser/web/chunks/BPD0kAZB.js +1 -0
- package/browser/web/chunks/BQeduZqT.js +1 -0
- package/browser/web/chunks/B_CVFyiz.js +1 -0
- package/browser/web/chunks/B_ns1YHO.js +1 -0
- package/browser/web/chunks/BcwkVTsR.js +1 -0
- package/browser/web/chunks/BeaQ6TYM.js +1 -0
- package/browser/web/chunks/BgBB013u.js +1 -0
- package/browser/web/chunks/BgsKhHDm.js +1 -0
- package/browser/web/chunks/BjMcbuhi.js +9 -0
- package/browser/web/chunks/Bjiy_F2N.js +1 -0
- package/browser/web/chunks/BqScCLwv.js +1 -0
- package/browser/web/chunks/BqX3Utqx.js +1 -0
- package/browser/web/chunks/BtVkQf3z.js +1 -0
- package/browser/web/chunks/By30h-7B.js +1 -0
- package/browser/web/chunks/C1zqYpy2.js +1 -0
- package/browser/web/chunks/C436juFf.js +1 -0
- package/browser/web/chunks/C4_bULs1.js +1 -0
- package/browser/web/chunks/C4omqJEz.js +1 -0
- package/browser/web/chunks/C7tt0T3n.js +1 -0
- package/browser/web/chunks/C8w7s5dg.js +1 -0
- package/browser/web/chunks/CElY4erO.js +1 -0
- package/browser/web/chunks/CFODo-m2.js +1 -0
- package/browser/web/chunks/CL4wjam9.js +1 -0
- package/browser/web/chunks/CMg-8UVf.js +1 -0
- package/browser/web/chunks/COWKfakj.js +1 -0
- package/browser/web/chunks/CQBU0qZ4.js +1 -0
- package/browser/web/chunks/CV6uABgc.js +1 -0
- package/browser/web/chunks/C_SWFpWQ.js +1 -0
- package/browser/web/chunks/C_Uanbrl.js +1 -0
- package/browser/web/chunks/Ce_CSanC.js +1 -0
- package/browser/web/chunks/Cg-ZmRhS.js +1 -0
- package/browser/web/chunks/Cgf2wPI_.js +1 -0
- package/browser/web/chunks/Cuep_3Vf.js +1 -0
- package/browser/web/chunks/D02PaHn6.js +1 -0
- package/browser/web/chunks/D5LiaI5R.js +1 -0
- package/browser/web/chunks/D9UgVYvF.js +1 -0
- package/browser/web/chunks/DC08tnkE.js +2 -0
- package/browser/web/chunks/DG8YGSvu.js +1 -0
- package/browser/web/chunks/DIQd0FYD.js +1 -0
- package/browser/web/chunks/DMLqacE8.js +1 -0
- package/browser/web/chunks/DSUI3yI-.js +1 -0
- package/browser/web/chunks/DT3Hb76X.js +1 -0
- package/browser/web/chunks/DY75g3-W.js +1 -0
- package/browser/web/chunks/DZpNQKZ9.js +1 -0
- package/browser/web/chunks/Db-W1wrC.js +1 -0
- package/browser/web/chunks/Dc1xK3Ii.js +1 -0
- package/browser/web/chunks/DdF6awFs.js +1 -0
- package/browser/web/chunks/DdaCLml8.js +1 -0
- package/browser/web/chunks/Dh8MLjQO.js +1 -0
- package/browser/web/chunks/DiuslJRy.js +1 -0
- package/browser/web/chunks/DjRcw3Y0.js +1 -0
- package/browser/web/chunks/Djdv-16J.js +1 -0
- package/browser/web/chunks/DnFXe_lF.js +1 -0
- package/browser/web/chunks/DneGv1oC.js +1 -0
- package/browser/web/chunks/DsVxP-p-.js +1 -0
- package/browser/web/chunks/DwDilCo2.js +1 -0
- package/browser/web/chunks/DwV48AXv.js +1 -0
- package/browser/web/chunks/F37aF4-L.js +1 -0
- package/browser/web/chunks/LyB6XIbN.js +1 -0
- package/browser/web/chunks/NKnbYGjC.js +1 -0
- package/browser/web/chunks/Vk-rVi16.js +1 -0
- package/browser/web/chunks/XsM0J1Ex.js +1 -0
- package/browser/web/chunks/asSN9iEp.js +1 -0
- package/browser/web/chunks/c-AjHfdF.js +1 -0
- package/browser/web/chunks/dR-12TPY.js +1 -0
- package/browser/web/chunks/hR4xM0EC.js +1 -0
- package/browser/web/chunks/hqOaBxAg.js +1 -0
- package/browser/web/chunks/kMKqqeG4.js +1 -0
- package/browser/web/chunks/kXboBcfi.js +1 -0
- package/browser/web/chunks/l4aQIg22.js +1 -0
- package/browser/web/chunks/tJC0JSU4.js +1 -0
- package/browser/web/chunks/wHdS_QYM.js +1 -0
- package/browser/web/chunks/yv8dTvNI.js +1 -0
- package/browser/web/chunks/yw9M3nfi.js +1 -0
- package/browser/web/collapsible.js +1 -0
- package/browser/web/color-picker.js +1 -0
- package/browser/web/combobox.js +2 -0
- package/browser/web/command.js +1 -0
- package/browser/web/core.js +5 -0
- package/browser/web/date-input.js +1 -0
- package/browser/web/date-picker.js +1 -0
- package/browser/web/dialog.js +1 -0
- package/browser/web/drawer.js +1 -0
- package/browser/web/field.js +1 -0
- package/browser/web/file-input.js +1 -0
- package/browser/web/hover-card.js +1 -0
- package/browser/web/image-cropper.js +1 -0
- package/browser/web/input.js +1 -0
- package/browser/web/label.js +1 -0
- package/browser/web/listbox.js +1 -0
- package/browser/web/menu.js +1 -0
- package/browser/web/menubar.js +1 -0
- package/browser/web/meter.js +1 -0
- package/browser/web/navigation-menu.js +1 -0
- package/browser/web/number-input.js +1 -0
- package/browser/web/otp-input.js +2 -0
- package/browser/web/overlays.js +1 -0
- package/browser/web/pagination.js +1 -0
- package/browser/web/password-input.js +1 -0
- package/browser/web/popover.js +1 -0
- package/browser/web/preferences.js +1 -0
- package/browser/web/progress.js +1 -0
- package/browser/web/radio.js +1 -0
- package/browser/web/rating.js +1 -0
- package/browser/web/resizable.js +1 -0
- package/browser/web/scroll-area.js +1 -0
- package/browser/web/segmented-control.js +1 -0
- package/browser/web/select.js +1 -0
- package/browser/web/separator.js +1 -0
- package/browser/web/slider.js +1 -0
- package/browser/web/switch.js +1 -0
- package/browser/web/tabs.js +1 -0
- package/browser/web/textarea.js +1 -0
- package/browser/web/time-input.js +1 -0
- package/browser/web/timeline.js +1 -0
- package/browser/web/toast.js +1 -0
- package/browser/web/toggle.js +1 -0
- package/browser/web/token-input.js +8 -0
- package/browser/web/toolbar.js +1 -0
- package/browser/web/tooltip.js +1 -0
- package/browser/web/tree.js +1 -0
- package/browser/web/trigger-menu.js +4 -0
- package/browser/web/waterfall.js +1 -0
- package/browser/web.css +3378 -0
- package/browser/web.js +3 -0
- package/custom-elements.json +32315 -0
- package/dist/accordion.d.ts +2 -0
- package/dist/accordion.js +57 -0
- package/dist/action.d.ts +16 -0
- package/dist/action.js +39 -0
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +7 -0
- package/dist/autocomplete.d.ts +2 -0
- package/dist/autocomplete.js +120 -0
- package/dist/autoload.d.ts +18 -0
- package/dist/autoload.js +63 -0
- package/dist/avatar.d.ts +2 -0
- package/dist/avatar.js +27 -0
- package/dist/browser-core.d.ts +2 -0
- package/dist/browser-core.js +8 -0
- package/dist/button.d.ts +2 -0
- package/dist/button.js +35 -0
- package/dist/calendar.d.ts +23 -0
- package/dist/calendar.js +429 -0
- package/dist/carousel.d.ts +2 -0
- package/dist/carousel.js +54 -0
- package/dist/checkbox.d.ts +4 -0
- package/dist/checkbox.js +75 -0
- package/dist/collapsible.d.ts +2 -0
- package/dist/collapsible.js +28 -0
- package/dist/color-picker.d.ts +2 -0
- package/dist/color-picker.js +64 -0
- package/dist/combobox.d.ts +2 -0
- package/dist/combobox.js +334 -0
- package/dist/command.d.ts +2 -0
- package/dist/command.js +122 -0
- package/dist/date-input.d.ts +3 -0
- package/dist/date-input.js +87 -0
- package/dist/date-picker.d.ts +2 -0
- package/dist/date-picker.js +174 -0
- package/dist/default-text.d.ts +3 -0
- package/dist/default-text.js +24 -0
- package/dist/define-element.d.ts +404 -0
- package/dist/define-element.js +1489 -0
- package/dist/dialog.d.ts +3 -0
- package/dist/dialog.js +94 -0
- package/dist/drawer.d.ts +2 -0
- package/dist/drawer.js +96 -0
- package/dist/entries/accordion.d.ts +3 -0
- package/dist/entries/accordion.js +7 -0
- package/dist/entries/alert-dialog.d.ts +3 -0
- package/dist/entries/alert-dialog.js +13 -0
- package/dist/entries/autocomplete.d.ts +3 -0
- package/dist/entries/autocomplete.js +7 -0
- package/dist/entries/avatar.d.ts +2 -0
- package/dist/entries/avatar.js +3 -0
- package/dist/entries/button.d.ts +2 -0
- package/dist/entries/button.js +3 -0
- package/dist/entries/calendar.d.ts +3 -0
- package/dist/entries/calendar.js +7 -0
- package/dist/entries/carousel.d.ts +3 -0
- package/dist/entries/carousel.js +7 -0
- package/dist/entries/checkbox.d.ts +3 -0
- package/dist/entries/checkbox.js +15 -0
- package/dist/entries/collapsible.d.ts +3 -0
- package/dist/entries/collapsible.js +7 -0
- package/dist/entries/color-picker.d.ts +3 -0
- package/dist/entries/color-picker.js +7 -0
- package/dist/entries/combobox.d.ts +3 -0
- package/dist/entries/combobox.js +7 -0
- package/dist/entries/command.d.ts +3 -0
- package/dist/entries/command.js +7 -0
- package/dist/entries/date-input.d.ts +3 -0
- package/dist/entries/date-input.js +7 -0
- package/dist/entries/date-picker.d.ts +3 -0
- package/dist/entries/date-picker.js +7 -0
- package/dist/entries/dialog.d.ts +3 -0
- package/dist/entries/dialog.js +7 -0
- package/dist/entries/drawer.d.ts +3 -0
- package/dist/entries/drawer.js +8 -0
- package/dist/entries/field.d.ts +2 -0
- package/dist/entries/field.js +3 -0
- package/dist/entries/file-input.d.ts +3 -0
- package/dist/entries/file-input.js +13 -0
- package/dist/entries/hover-card.d.ts +3 -0
- package/dist/entries/hover-card.js +7 -0
- package/dist/entries/image-cropper.d.ts +3 -0
- package/dist/entries/image-cropper.js +7 -0
- package/dist/entries/input.d.ts +3 -0
- package/dist/entries/input.js +8 -0
- package/dist/entries/label.d.ts +2 -0
- package/dist/entries/label.js +3 -0
- package/dist/entries/listbox.d.ts +3 -0
- package/dist/entries/listbox.js +7 -0
- package/dist/entries/menu.d.ts +3 -0
- package/dist/entries/menu.js +7 -0
- package/dist/entries/menubar.d.ts +3 -0
- package/dist/entries/menubar.js +7 -0
- package/dist/entries/meter.d.ts +2 -0
- package/dist/entries/meter.js +3 -0
- package/dist/entries/navigation-menu.d.ts +3 -0
- package/dist/entries/navigation-menu.js +7 -0
- package/dist/entries/number-input.d.ts +3 -0
- package/dist/entries/number-input.js +7 -0
- package/dist/entries/otp-input.d.ts +3 -0
- package/dist/entries/otp-input.js +7 -0
- package/dist/entries/overlays.d.ts +2 -0
- package/dist/entries/overlays.js +3 -0
- package/dist/entries/pagination.d.ts +3 -0
- package/dist/entries/pagination.js +11 -0
- package/dist/entries/password-input.d.ts +3 -0
- package/dist/entries/password-input.js +7 -0
- package/dist/entries/popover.d.ts +3 -0
- package/dist/entries/popover.js +7 -0
- package/dist/entries/preferences.d.ts +3 -0
- package/dist/entries/preferences.js +13 -0
- package/dist/entries/progress.d.ts +2 -0
- package/dist/entries/progress.js +3 -0
- package/dist/entries/radio.d.ts +3 -0
- package/dist/entries/radio.js +7 -0
- package/dist/entries/rating.d.ts +3 -0
- package/dist/entries/rating.js +8 -0
- package/dist/entries/resizable.d.ts +3 -0
- package/dist/entries/resizable.js +11 -0
- package/dist/entries/scroll-area.d.ts +3 -0
- package/dist/entries/scroll-area.js +7 -0
- package/dist/entries/segmented-control.d.ts +3 -0
- package/dist/entries/segmented-control.js +7 -0
- package/dist/entries/select.d.ts +3 -0
- package/dist/entries/select.js +7 -0
- package/dist/entries/separator.d.ts +2 -0
- package/dist/entries/separator.js +3 -0
- package/dist/entries/slider.d.ts +3 -0
- package/dist/entries/slider.js +7 -0
- package/dist/entries/switch.d.ts +3 -0
- package/dist/entries/switch.js +7 -0
- package/dist/entries/tabs.d.ts +3 -0
- package/dist/entries/tabs.js +7 -0
- package/dist/entries/textarea.d.ts +3 -0
- package/dist/entries/textarea.js +7 -0
- package/dist/entries/time-input.d.ts +3 -0
- package/dist/entries/time-input.js +7 -0
- package/dist/entries/timeline.d.ts +3 -0
- package/dist/entries/timeline.js +7 -0
- package/dist/entries/toast.d.ts +2 -0
- package/dist/entries/toast.js +3 -0
- package/dist/entries/toggle.d.ts +3 -0
- package/dist/entries/toggle.js +12 -0
- package/dist/entries/token-input.d.ts +3 -0
- package/dist/entries/token-input.js +17 -0
- package/dist/entries/toolbar.d.ts +3 -0
- package/dist/entries/toolbar.js +7 -0
- package/dist/entries/tooltip.d.ts +3 -0
- package/dist/entries/tooltip.js +7 -0
- package/dist/entries/tree.d.ts +3 -0
- package/dist/entries/tree.js +17 -0
- package/dist/entries/trigger-menu.d.ts +3 -0
- package/dist/entries/trigger-menu.js +11 -0
- package/dist/entries/waterfall.d.ts +3 -0
- package/dist/entries/waterfall.js +11 -0
- package/dist/events.d.ts +1658 -0
- package/dist/events.js +0 -0
- package/dist/field.d.ts +2 -0
- package/dist/field.js +101 -0
- package/dist/file-input.d.ts +2 -0
- package/dist/file-input.js +140 -0
- package/dist/forward-attributes.d.ts +2 -0
- package/dist/forward-attributes.js +22 -0
- package/dist/history.d.ts +2 -0
- package/dist/history.js +11 -0
- package/dist/hover-card.d.ts +2 -0
- package/dist/hover-card.js +31 -0
- package/dist/image-cropper.d.ts +2 -0
- package/dist/image-cropper.js +66 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.js +269 -0
- package/dist/input.d.ts +3 -0
- package/dist/input.js +69 -0
- package/dist/label.d.ts +2 -0
- package/dist/label.js +11 -0
- package/dist/list.d.ts +40 -0
- package/dist/list.js +192 -0
- package/dist/listbox.d.ts +2 -0
- package/dist/listbox.js +84 -0
- package/dist/menu.d.ts +4 -0
- package/dist/menu.js +295 -0
- package/dist/menubar.d.ts +4 -0
- package/dist/menubar.js +30 -0
- package/dist/meter.d.ts +2 -0
- package/dist/meter.js +22 -0
- package/dist/navigation-menu.d.ts +2 -0
- package/dist/navigation-menu.js +114 -0
- package/dist/number-input.d.ts +2 -0
- package/dist/number-input.js +73 -0
- package/dist/observe.d.ts +2 -0
- package/dist/observe.js +7 -0
- package/dist/otp-input.d.ts +2 -0
- package/dist/otp-input.js +72 -0
- package/dist/overlays.d.ts +13 -0
- package/dist/overlays.js +156 -0
- package/dist/pagination.d.ts +2 -0
- package/dist/pagination.js +127 -0
- package/dist/password-input.d.ts +2 -0
- package/dist/password-input.js +57 -0
- package/dist/popover.d.ts +2 -0
- package/dist/popover.js +64 -0
- package/dist/popup.d.ts +40 -0
- package/dist/popup.js +112 -0
- package/dist/preferences.d.ts +2 -0
- package/dist/preferences.js +56 -0
- package/dist/progress.d.ts +2 -0
- package/dist/progress.js +22 -0
- package/dist/radio.d.ts +2 -0
- package/dist/radio.js +33 -0
- package/dist/rating.d.ts +2 -0
- package/dist/rating.js +64 -0
- package/dist/resizable.d.ts +2 -0
- package/dist/resizable.js +42 -0
- package/dist/scroll-area.d.ts +2 -0
- package/dist/scroll-area.js +45 -0
- package/dist/segmented-control.d.ts +2 -0
- package/dist/segmented-control.js +28 -0
- package/dist/select.d.ts +2 -0
- package/dist/select.js +239 -0
- package/dist/separator.d.ts +2 -0
- package/dist/separator.js +11 -0
- package/dist/slider.d.ts +2 -0
- package/dist/slider.js +77 -0
- package/dist/tabs.d.ts +2 -0
- package/dist/tabs.js +37 -0
- package/dist/timeline.d.ts +2 -0
- package/dist/timeline.js +27 -0
- package/dist/toast.d.ts +20 -0
- package/dist/toast.js +177 -0
- package/dist/toggle.d.ts +3 -0
- package/dist/toggle.js +64 -0
- package/dist/token-input.d.ts +2 -0
- package/dist/token-input.js +103 -0
- package/dist/toolbar.d.ts +2 -0
- package/dist/toolbar.js +36 -0
- package/dist/tooltip.d.ts +2 -0
- package/dist/tooltip.js +35 -0
- package/dist/tree.d.ts +2 -0
- package/dist/tree.js +147 -0
- package/dist/trigger-menu.d.ts +2 -0
- package/dist/trigger-menu.js +133 -0
- package/dist/waterfall.d.ts +2 -0
- package/dist/waterfall.js +140 -0
- package/docs/README.md +89 -0
- package/docs/agents.md +1523 -0
- package/docs/components/accordion.md +1401 -0
- package/docs/components/alert-dialog.md +788 -0
- package/docs/components/autocomplete.md +1692 -0
- package/docs/components/avatar.md +261 -0
- package/docs/components/button.md +441 -0
- package/docs/components/calendar.md +1536 -0
- package/docs/components/carousel.md +1055 -0
- package/docs/components/checkbox.md +1045 -0
- package/docs/components/collapsible.md +535 -0
- package/docs/components/color-picker.md +651 -0
- package/docs/components/combobox.md +3274 -0
- package/docs/components/command.md +1431 -0
- package/docs/components/date-input.md +563 -0
- package/docs/components/date-picker.md +1136 -0
- package/docs/components/dialog.md +1360 -0
- package/docs/components/drawer.md +1201 -0
- package/docs/components/field.md +519 -0
- package/docs/components/file-input.md +617 -0
- package/docs/components/hover-card.md +486 -0
- package/docs/components/image-cropper.md +489 -0
- package/docs/components/input.md +327 -0
- package/docs/components/label.md +208 -0
- package/docs/components/listbox.md +1015 -0
- package/docs/components/menu.md +1212 -0
- package/docs/components/menubar.md +460 -0
- package/docs/components/meter.md +298 -0
- package/docs/components/navigation-menu.md +1573 -0
- package/docs/components/number-input.md +1087 -0
- package/docs/components/otp-input.md +558 -0
- package/docs/components/pagination.md +639 -0
- package/docs/components/password-input.md +649 -0
- package/docs/components/popover.md +1433 -0
- package/docs/components/preferences.md +243 -0
- package/docs/components/progress.md +406 -0
- package/docs/components/radio.md +855 -0
- package/docs/components/rating.md +431 -0
- package/docs/components/resizable.md +866 -0
- package/docs/components/scroll-area.md +898 -0
- package/docs/components/segmented-control.md +421 -0
- package/docs/components/select.md +1957 -0
- package/docs/components/separator.md +238 -0
- package/docs/components/slider.md +1018 -0
- package/docs/components/switch.md +583 -0
- package/docs/components/tabs.md +948 -0
- package/docs/components/textarea.md +331 -0
- package/docs/components/time-input.md +235 -0
- package/docs/components/timeline.md +622 -0
- package/docs/components/toast.md +1223 -0
- package/docs/components/toggle.md +522 -0
- package/docs/components/token-input.md +854 -0
- package/docs/components/toolbar.md +815 -0
- package/docs/components/tooltip.md +860 -0
- package/docs/components/tree.md +1243 -0
- package/docs/components/trigger-menu.md +1110 -0
- package/docs/components/waterfall.md +709 -0
- package/docs/controllers.md +66 -0
- package/docs/core.md +8027 -0
- package/docs/custom-parts.md +91 -0
- package/docs/first-component.md +88 -0
- package/docs/forms.md +125 -0
- package/docs/installation.md +141 -0
- package/docs/introduction.md +32 -0
- package/docs/lists-and-menus.md +166 -0
- package/docs/llms.txt +1566 -0
- package/docs/parts-and-composition.md +57 -0
- package/docs/popups.md +92 -0
- package/docs/rendering.md +71 -0
- package/docs/server-rendering.md +118 -0
- package/docs/state-and-events.md +134 -0
- package/docs/styling-and-animation.md +104 -0
- package/docs/utilities/async-options.md +332 -0
- package/docs/utilities/shortcuts.md +184 -0
- package/html-custom-data.json +14792 -0
- package/package.json +302 -3
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
# Input
|
|
2
|
+
|
|
3
|
+
Enter text, add a clear button, and connect the value to your form or state.
|
|
4
|
+
|
|
5
|
+
An input is a native text field for short values like a name, an email address or a search. It works inside a field and a form, and adds a clear button, text around the input, and change reasons.
|
|
6
|
+
|
|
7
|
+
```ts title="basic.ts"
|
|
8
|
+
import "@ui-sdk/web/field"
|
|
9
|
+
import "@ui-sdk/web/input"
|
|
10
|
+
import { X, createElement } from "lucide"
|
|
11
|
+
import { log } from "./log"
|
|
12
|
+
|
|
13
|
+
function mount(root: HTMLElement) {
|
|
14
|
+
root.innerHTML = `
|
|
15
|
+
<ui-field name="website">
|
|
16
|
+
<ui-field-label>Website</ui-field-label>
|
|
17
|
+
<ui-input-group>
|
|
18
|
+
<span>https://</span>
|
|
19
|
+
<ui-input>
|
|
20
|
+
<input placeholder="example.com" value="hollisgrant.com" />
|
|
21
|
+
</ui-input>
|
|
22
|
+
<ui-input-clear>
|
|
23
|
+
<button type="button" aria-label="Clear website">
|
|
24
|
+
${createElement(X, { "aria-hidden": "true" }).outerHTML}
|
|
25
|
+
</button>
|
|
26
|
+
</ui-input-clear>
|
|
27
|
+
</ui-input-group>
|
|
28
|
+
<ui-field-description>Shown on your public profile.</ui-field-description>
|
|
29
|
+
</ui-field>
|
|
30
|
+
`
|
|
31
|
+
root.querySelector("ui-input")!.addEventListener("valuechange", (event) => {
|
|
32
|
+
const { value, reason } = event.detail
|
|
33
|
+
log(root, `${value ? `“${value}”` : "Empty"} (${reason})`)
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { mount }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Edit the website, then press Clear website. The text clears, focus returns to the input and the console logs the reason. Pressing https:// focuses the input too.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install @ui-sdk/web @ui-sdk/core
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Importing the component defines its elements. On the server the import does nothing.
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import "@ui-sdk/web/input"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Composition
|
|
55
|
+
|
|
56
|
+
Use the following composition to build a `ui-input` or a `ui-input-group`:
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
ui-input
|
|
60
|
+
└── input
|
|
61
|
+
|
|
62
|
+
ui-input-group
|
|
63
|
+
├── ui-input
|
|
64
|
+
│ └── input
|
|
65
|
+
└── ui-input-clear
|
|
66
|
+
└── button
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`<ui-input>` wraps your own `<input>`, so put its type, placeholder, autocomplete and other native attributes on the input. `<ui-input-group>` holds text or buttons around it, and `<ui-input-clear>` wraps a button that empties it.
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
Import the parts and put them together:
|
|
74
|
+
|
|
75
|
+
```html
|
|
76
|
+
<script type="module">
|
|
77
|
+
import "@ui-sdk/web/input"
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<ui-input-group>
|
|
81
|
+
<ui-input><input type="search" aria-label="Search" /></ui-input>
|
|
82
|
+
<ui-input-clear
|
|
83
|
+
><button type="button" aria-label="Clear search"></button
|
|
84
|
+
></ui-input-clear>
|
|
85
|
+
</ui-input-group>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Fields
|
|
89
|
+
|
|
90
|
+
Wrap the input in a [Field](./field.md) to give it a visible label, a description and errors. The field also supplies its `name` when the input has none.
|
|
91
|
+
|
|
92
|
+
```html
|
|
93
|
+
<ui-field name="username">
|
|
94
|
+
<ui-field-label>Username</ui-field-label>
|
|
95
|
+
<ui-input><input autocomplete="username" /></ui-input>
|
|
96
|
+
<ui-field-description
|
|
97
|
+
>Choose a unique username for your account.</ui-field-description
|
|
98
|
+
>
|
|
99
|
+
</ui-field>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Disabled and Read Only
|
|
103
|
+
|
|
104
|
+
Set `disabled` on the input or its field to prevent editing and leave it out of the tab order and the submitted values. A `readonly` input can still be focused, selected and submitted.
|
|
105
|
+
|
|
106
|
+
```html
|
|
107
|
+
<ui-field disabled>
|
|
108
|
+
<ui-field-label>Email</ui-field-label>
|
|
109
|
+
<ui-input><input type="email" value="hollis@example.com" /></ui-input>
|
|
110
|
+
</ui-field>
|
|
111
|
+
|
|
112
|
+
<ui-field>
|
|
113
|
+
<ui-field-label>Profile URL</ui-field-label>
|
|
114
|
+
<ui-input><input readonly value="example.com/hollis" /></ui-input>
|
|
115
|
+
</ui-field>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Validation
|
|
119
|
+
|
|
120
|
+
Use native constraints such as `required`, `type="email"` and `pattern`. The field shows its error after a submit attempt and updates it as the value changes. Set the field's `invalid` property for an error your app decides; the input gets `aria-invalid`. [Field](./field.md#validation) covers the error parts and their matches.
|
|
121
|
+
|
|
122
|
+
```html
|
|
123
|
+
<ui-field name="email">
|
|
124
|
+
<ui-field-label>Email</ui-field-label>
|
|
125
|
+
<ui-input><input type="email" required /></ui-input>
|
|
126
|
+
<ui-field-error match="valueMissing"
|
|
127
|
+
>Enter your email address.</ui-field-error
|
|
128
|
+
>
|
|
129
|
+
<ui-field-error match="true">That email is already in use.</ui-field-error>
|
|
130
|
+
</ui-field>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
document.querySelector("ui-field")!.invalid = emailTaken ? true : undefined
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Input Group
|
|
138
|
+
|
|
139
|
+
Place text or buttons around an input with `<ui-input-group>`. Pressing the group's text focuses the input. The text is display content, not part of the submitted value.
|
|
140
|
+
|
|
141
|
+
```html
|
|
142
|
+
<ui-input-group>
|
|
143
|
+
<span>https://</span>
|
|
144
|
+
<ui-input><input aria-label="Website" placeholder="example" /></ui-input>
|
|
145
|
+
<span>.com</span>
|
|
146
|
+
</ui-input-group>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Clear Button
|
|
150
|
+
|
|
151
|
+
`<ui-input-clear>` shows while the input has text it can clear. Pressing its button empties the value, reports `clear-press` and returns focus to the input. `valuechange` and native `input` listeners receive the change too.
|
|
152
|
+
|
|
153
|
+
```html
|
|
154
|
+
<ui-input-group>
|
|
155
|
+
<ui-input><input type="search" aria-label="Search people" /></ui-input>
|
|
156
|
+
<ui-input-clear>
|
|
157
|
+
<button type="button" aria-label="Clear search">
|
|
158
|
+
<svg aria-hidden="true">…</svg>
|
|
159
|
+
</button>
|
|
160
|
+
</ui-input-clear>
|
|
161
|
+
</ui-input-group>
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Controlled
|
|
165
|
+
|
|
166
|
+
Set the element's `value` property and listen for `valuechange` to keep the text in your own state. Native `input` events still work.
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
const input = document.querySelector("ui-input")!
|
|
170
|
+
input.value = "Hollis Grant"
|
|
171
|
+
input.addEventListener("valuechange", (event) => setName(event.detail.value))
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
See [State and Events](../state-and-events.md) for the shared controlled-state conventions. Input's [reasons](#reasons) tell typing, clearing, resetting and controller changes apart.
|
|
175
|
+
|
|
176
|
+
## Filtering What's Typed
|
|
177
|
+
|
|
178
|
+
Call `event.preventDefault()` in the `valuechange` listener to reject a change. The previous text and caret position are restored.
|
|
179
|
+
|
|
180
|
+
```html
|
|
181
|
+
<ui-input><input inputmode="numeric" maxlength="6" /></ui-input>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
input.addEventListener("valuechange", (event) => {
|
|
186
|
+
if (!/^\d*$/.test(event.detail.value)) event.preventDefault()
|
|
187
|
+
})
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Controller
|
|
191
|
+
|
|
192
|
+
Use the element's `api` for actions outside the input. Its methods update the input through the same `valuechange` events as typing.
|
|
193
|
+
|
|
194
|
+
```html
|
|
195
|
+
<ui-input><input aria-label="Message" /></ui-input>
|
|
196
|
+
<button type="button" data-action="reply">Quick Reply</button>
|
|
197
|
+
<button type="button" data-action="clear">Clear</button>
|
|
198
|
+
<button type="button" data-action="focus">Focus</button>
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
const message = document.querySelector("ui-input")!.api
|
|
203
|
+
document
|
|
204
|
+
.querySelector('[data-action="reply"]')!
|
|
205
|
+
.addEventListener("click", () => message.setValue("On my way!"))
|
|
206
|
+
document
|
|
207
|
+
.querySelector('[data-action="clear"]')!
|
|
208
|
+
.addEventListener("click", () => message.clear())
|
|
209
|
+
document
|
|
210
|
+
.querySelector('[data-action="focus"]')!
|
|
211
|
+
.addEventListener("click", () => message.focus())
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
[Controllers](../controllers.md) covers an element's `api`.
|
|
215
|
+
|
|
216
|
+
## Passwords and Files
|
|
217
|
+
|
|
218
|
+
Use [Password Input](./password-input.md) to show and hide a password. A native file input works with `type="file"`; use [File Input](./file-input.md) for dropping, previews and validation.
|
|
219
|
+
|
|
220
|
+
## Styling
|
|
221
|
+
|
|
222
|
+
Each part has a `data-slot`, such as `input-group`, and shows its state through the attributes listed under [Data Attributes](#data-attributes). Use `data-filled`, `data-disabled`, `data-readonly` and `data-required` on the input, and the field's validation and focus attributes inside a field. For a group's focus ring, style `:has(input:focus-visible)`, so a focused button inside it keeps its own ring.
|
|
223
|
+
|
|
224
|
+
## Data Attributes
|
|
225
|
+
|
|
226
|
+
### `<ui-input>`
|
|
227
|
+
`[data-slot="input"]`
|
|
228
|
+
|
|
229
|
+
- `data-filled`: Present while the field holds any text.
|
|
230
|
+
- `data-disabled`: Present when the field is disabled, by its own prop or its Field.
|
|
231
|
+
- `data-readonly`: Present when the field is read-only.
|
|
232
|
+
- `data-required`: Present when the field is required.
|
|
233
|
+
|
|
234
|
+
### `<ui-input-group>`
|
|
235
|
+
`[data-slot="input-group"]`
|
|
236
|
+
|
|
237
|
+
- `data-filled`: Present while the field in the group holds any text.
|
|
238
|
+
- `data-disabled`: Present while the field in the group is disabled, by itself or a `<fieldset>`.
|
|
239
|
+
- `data-readonly`: Present while the field in the group is read-only.
|
|
240
|
+
|
|
241
|
+
### `<ui-input-clear>`
|
|
242
|
+
`[data-slot="input-clear"]`
|
|
243
|
+
|
|
244
|
+
- `data-filled`: Present while the field in the group holds any text.
|
|
245
|
+
- `data-disabled`: Present while the field in the group is disabled, by itself or a `<fieldset>`.
|
|
246
|
+
- `data-readonly`: Present while the field in the group is read-only.
|
|
247
|
+
|
|
248
|
+
## API Reference
|
|
249
|
+
|
|
250
|
+
Put native attributes on the `<input>`, where `value` is the default. The `<ui-input>` element's `value` property reads and writes the text, and its `api` has the controller's methods. `onValueChange` is the `valuechange` event, which doesn't bubble: `event.detail` has the `value` and the `reason`, and `preventDefault()` cancels the change.
|
|
251
|
+
|
|
252
|
+
### Input
|
|
253
|
+
|
|
254
|
+
- `value?` (`string`): The value, for a controlled field.
|
|
255
|
+
- `defaultValue?` (`string`): The value it starts with. A form reset returns here.
|
|
256
|
+
- `valuechange event`: Called when the user changes the value: typing (`"input-change"`), a Clear part (`"clear-press"`), a form reset (`"reset"`) or a controller (`"imperative"`). `details.cancel()` keeps the value as it was.
|
|
257
|
+
- `controller?` (`object`): Reads and writes the field from anywhere. Create one with `createInputController()`.
|
|
258
|
+
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
|
|
259
|
+
|
|
260
|
+
- `disabled?` (`boolean`): Disables the field.
|
|
261
|
+
- `readOnly?` (`boolean`): Makes the field read-only.
|
|
262
|
+
- `required?` (`boolean`): Makes the field required.
|
|
263
|
+
|
|
264
|
+
### InputGroup
|
|
265
|
+
|
|
266
|
+
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
|
|
267
|
+
|
|
268
|
+
### InputClear
|
|
269
|
+
|
|
270
|
+
Wraps a `<button>` that empties the input in its group and focuses it. It shows only while there's text to clear.
|
|
271
|
+
|
|
272
|
+
### State
|
|
273
|
+
|
|
274
|
+
- `filled` (`boolean`): Whether the field holds any text.
|
|
275
|
+
- `disabled` (`boolean`): Whether the field is disabled.
|
|
276
|
+
- `readOnly` (`boolean`): Whether the field is read-only.
|
|
277
|
+
- `required` (`boolean`): Whether the field is required.
|
|
278
|
+
|
|
279
|
+
`<ui-input-group>` and `<ui-input-clear>` receive the state of the input inside the group.
|
|
280
|
+
|
|
281
|
+
- `filled` (`boolean`): Whether the field in the group holds any text.
|
|
282
|
+
- `disabled` (`boolean`): Whether the field in the group is disabled, by itself or by a `<fieldset>`.
|
|
283
|
+
- `readOnly` (`boolean`): Whether the field in the group is read-only.
|
|
284
|
+
|
|
285
|
+
### Reasons
|
|
286
|
+
|
|
287
|
+
- `input-change` (`Event`): Typing, pasting or dropping changed a text field's value; in a combobox it can also open or close it, or Enter keeps the typed text as the value.
|
|
288
|
+
- `clear-press` (`MouseEvent | KeyboardEvent`): A Clear part was pressed, like on an input, a select or a combobox.
|
|
289
|
+
- `reset` (`none`): A form reset.
|
|
290
|
+
- `imperative` (`none`): A controller or `api` call, or a property set on a web component.
|
|
291
|
+
|
|
292
|
+
### Controller
|
|
293
|
+
|
|
294
|
+
The `<ui-input>` element's `api` property has these methods.
|
|
295
|
+
|
|
296
|
+
- `getValue()` (`() => string`): The current value.
|
|
297
|
+
- `setValue(value, options?)` (`(value: string, options?: ChangeOptions<InputValueChangeReason> | undefined) => boolean`): Sets the value as if the user typed it, so `input` fires. Returns false when the change was canceled or nothing changed.
|
|
298
|
+
- `clear(options?)` (`(options?: ChangeOptions<InputValueChangeReason> | undefined) => boolean`): Empties the field, as if the user deleted the text, so `input` fires. Returns false when the change was canceled or nothing changed.
|
|
299
|
+
- `focus()` (`() => void`): Moves focus to the field.
|
|
300
|
+
|
|
301
|
+
## Accessibility
|
|
302
|
+
|
|
303
|
+
Give the input a visible field label or an `aria-label`, and give the clear button an accessible name. The native input keeps standard text editing, selection, autocomplete and form behavior.
|
|
304
|
+
|
|
305
|
+
- The label names the input and the description describes it.
|
|
306
|
+
- Clicking the label focuses the input.
|
|
307
|
+
- An invalid input is marked once the form tries to submit.
|
|
308
|
+
- Data-filled follows the text.
|
|
309
|
+
- An input group's clear button shows only while there's text.
|
|
310
|
+
- <ui-input>'s value property writes the field quietly, and its api reports. Web components only.
|
|
311
|
+
|
|
312
|
+
**Enhancements**
|
|
313
|
+
|
|
314
|
+
- Changes report their reason: typing, then a reset.
|
|
315
|
+
- A canceled change keeps the text as it was.
|
|
316
|
+
- A canceled change keeps a controlled input's text as it was.
|
|
317
|
+
- A canceled change waits for an IME to finish before the text goes back.
|
|
318
|
+
- A controlled input keeps every keystroke.
|
|
319
|
+
- A required input marks its label required.
|
|
320
|
+
|
|
321
|
+
**Input group**
|
|
322
|
+
|
|
323
|
+
- The clear button empties the field, reports why, and returns focus.
|
|
324
|
+
- Pressing the group's text focuses its field.
|
|
325
|
+
- The clear button hides while its field is disabled.
|
|
326
|
+
|
|
327
|
+
Runs in React, Vue and web components.
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# Label
|
|
2
|
+
|
|
3
|
+
Name any control with a label, and let a press on the label reach it.
|
|
4
|
+
|
|
5
|
+
A plain `<label>` only reaches inputs, buttons and selects. `ui-label` names any control by its `for`, including a radio group or a slider, and a press on the label moves focus into it.
|
|
6
|
+
|
|
7
|
+
```ts title="basic.ts"
|
|
8
|
+
import "@ui-sdk/web/label"
|
|
9
|
+
import "@ui-sdk/web/radio"
|
|
10
|
+
|
|
11
|
+
const speeds = [
|
|
12
|
+
{ value: "standard", label: "Standard" },
|
|
13
|
+
{ value: "express", label: "Express" },
|
|
14
|
+
{ value: "overnight", label: "Overnight" },
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
function mount(root: HTMLElement) {
|
|
18
|
+
root.innerHTML = `
|
|
19
|
+
<div data-slot="stack">
|
|
20
|
+
<ui-label for="shipping-speed">Shipping speed</ui-label>
|
|
21
|
+
<ui-radio-group id="shipping-speed" default-value="standard">
|
|
22
|
+
${speeds
|
|
23
|
+
.map(
|
|
24
|
+
(speed) => `
|
|
25
|
+
<ui-label>
|
|
26
|
+
<ui-radio value="${speed.value}">
|
|
27
|
+
<ui-radio-indicator></ui-radio-indicator>
|
|
28
|
+
</ui-radio>
|
|
29
|
+
${speed.label}
|
|
30
|
+
</ui-label>
|
|
31
|
+
`
|
|
32
|
+
)
|
|
33
|
+
.join("")}
|
|
34
|
+
</ui-radio-group>
|
|
35
|
+
</div>
|
|
36
|
+
`
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { mount }
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Press Shipping speed. Focus moves to the checked option, and a screen reader names the group Shipping speed.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install @ui-sdk/web @ui-sdk/core
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Importing the component defines its element. On the server the import does nothing.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import "@ui-sdk/web/label"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
Import the label and point its `for` at the control's `id`:
|
|
59
|
+
|
|
60
|
+
```html
|
|
61
|
+
<script type="module">
|
|
62
|
+
import "@ui-sdk/web/label"
|
|
63
|
+
import "@ui-sdk/web/radio"
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<ui-label for="plan">Plan</ui-label>
|
|
67
|
+
<ui-radio-group id="plan" default-value="pro">
|
|
68
|
+
<ui-radio value="free">Free</ui-radio>
|
|
69
|
+
<ui-radio value="pro">Pro</ui-radio>
|
|
70
|
+
</ui-radio-group>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The control takes `ui-label` as its name, and a press on the label focuses it, checks it or clicks it, as a native label would.
|
|
74
|
+
|
|
75
|
+
Inside a [Field](./field.md), use `ui-field-label`, which also ties the field's description and errors to the control.
|
|
76
|
+
|
|
77
|
+
## Build Your Own
|
|
78
|
+
|
|
79
|
+
`@ui-sdk/web/label` comes with a ready-made `ui-label` element. If you'd like to build your own, with your own element name, start from the `label` primitive in `@ui-sdk/core`:
|
|
80
|
+
|
|
81
|
+
```ts title="caption-element.ts"
|
|
82
|
+
import { label } from "@ui-sdk/core/label"
|
|
83
|
+
import { createParts } from "@ui-sdk/web"
|
|
84
|
+
|
|
85
|
+
createParts(label, {
|
|
86
|
+
root: { tag: "app-caption" },
|
|
87
|
+
})
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
```html
|
|
91
|
+
<app-caption for="plan">Plan</app-caption>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`app-caption` keeps the behavior of the ready-made `ui-label`: it names the control and reaches it on a press. See [Rendering](../rendering.md) and [Custom Parts](../custom-parts.md) for more.
|
|
95
|
+
|
|
96
|
+
## Slider
|
|
97
|
+
|
|
98
|
+
A label for a slider names its thumb, so the thumb reads as **Volume**, and a press on the label focuses it.
|
|
99
|
+
|
|
100
|
+
```ts title="slider.ts"
|
|
101
|
+
import "@ui-sdk/web/label"
|
|
102
|
+
import "@ui-sdk/web/slider"
|
|
103
|
+
|
|
104
|
+
function mount(root: HTMLElement) {
|
|
105
|
+
root.innerHTML = `
|
|
106
|
+
<ui-slider id="volume" default-value="75">
|
|
107
|
+
<div data-slot="row">
|
|
108
|
+
<ui-label for="volume">Volume</ui-label>
|
|
109
|
+
<ui-slider-value></ui-slider-value>
|
|
110
|
+
</div>
|
|
111
|
+
<ui-slider-control>
|
|
112
|
+
<ui-slider-track>
|
|
113
|
+
<ui-slider-indicator></ui-slider-indicator>
|
|
114
|
+
<ui-slider-thumb></ui-slider-thumb>
|
|
115
|
+
</ui-slider-track>
|
|
116
|
+
</ui-slider-control>
|
|
117
|
+
</ui-slider>
|
|
118
|
+
`
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { mount }
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Press Volume, then use the arrow keys. The thumb moves, and a screen reader reads it as Volume.
|
|
125
|
+
|
|
126
|
+
## Switch
|
|
127
|
+
|
|
128
|
+
Point the label at a switch beside it. A press on the label turns the switch on and off.
|
|
129
|
+
|
|
130
|
+
```ts title="switch.ts"
|
|
131
|
+
import "@ui-sdk/web/label"
|
|
132
|
+
import "@ui-sdk/web/switch"
|
|
133
|
+
|
|
134
|
+
function mount(root: HTMLElement) {
|
|
135
|
+
root.innerHTML = `
|
|
136
|
+
<div data-slot="row">
|
|
137
|
+
<ui-switch id="updates">
|
|
138
|
+
<ui-switch-thumb></ui-switch-thumb>
|
|
139
|
+
</ui-switch>
|
|
140
|
+
<ui-label for="updates">Email me product updates</ui-label>
|
|
141
|
+
</div>
|
|
142
|
+
`
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export { mount }
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Press Email me product updates. The switch turns on.
|
|
149
|
+
|
|
150
|
+
## Wrapping a Control
|
|
151
|
+
|
|
152
|
+
Put the control inside the label instead of pointing at it, and you need no `id`.
|
|
153
|
+
|
|
154
|
+
```ts title="wrap.ts"
|
|
155
|
+
import "@ui-sdk/web/checkbox"
|
|
156
|
+
import "@ui-sdk/web/label"
|
|
157
|
+
import { Check, createElement } from "lucide"
|
|
158
|
+
|
|
159
|
+
function mount(root: HTMLElement) {
|
|
160
|
+
root.innerHTML = `
|
|
161
|
+
<ui-label>
|
|
162
|
+
<ui-checkbox>
|
|
163
|
+
<ui-checkbox-indicator>
|
|
164
|
+
${createElement(Check, { "aria-hidden": "true" }).outerHTML}
|
|
165
|
+
</ui-checkbox-indicator>
|
|
166
|
+
</ui-checkbox>
|
|
167
|
+
Accept terms and conditions
|
|
168
|
+
</ui-label>
|
|
169
|
+
`
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { mount }
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Press Accept terms and conditions. The checkbox checks, and a double click doesn't select the text.
|
|
176
|
+
|
|
177
|
+
## Styling
|
|
178
|
+
|
|
179
|
+
The label is unstyled. It has a `data-slot` of `label`.
|
|
180
|
+
|
|
181
|
+
A double click on the label doesn't select its text, so you don't need `user-select: none` for that.
|
|
182
|
+
|
|
183
|
+
## API Reference
|
|
184
|
+
|
|
185
|
+
Attributes are the same as below, along with `for`, which names the control's `id`.
|
|
186
|
+
|
|
187
|
+
### Label
|
|
188
|
+
|
|
189
|
+
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
|
|
190
|
+
|
|
191
|
+
## Accessibility
|
|
192
|
+
|
|
193
|
+
`ui-label` names its control through `aria-labelledby`, unless the control has an `aria-label` or an `aria-labelledby` of its own, which win. Its press does what a native label's does: it checks a checkbox, a switch or a radio, focuses a group's checked radio, and focuses anything else. A press on a disabled control does nothing.
|
|
194
|
+
|
|
195
|
+
### Tested Behavior
|
|
196
|
+
|
|
197
|
+
Every line below is an automated test.
|
|
198
|
+
|
|
199
|
+
- A label names a native input, and a press focuses it.
|
|
200
|
+
- A label names a radio group, and a press focuses its checked radio.
|
|
201
|
+
- A label for a slider names its thumb, and a press focuses it.
|
|
202
|
+
- A label around a checkbox names it, and a press toggles it.
|
|
203
|
+
- A press on the label of a disabled group moves no focus.
|
|
204
|
+
- A control its author names keeps that name.
|
|
205
|
+
- A label names a control that renders after it.
|
|
206
|
+
- A double click on a label doesn't select its text.
|
|
207
|
+
|
|
208
|
+
Runs in React, Vue and web components.
|