@slipstream-ui/core 0.8.0 → 0.10.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/index.d.mts +203 -8
- package/dist/index.d.ts +203 -8
- package/dist/index.js +1737 -965
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1729 -961
- package/dist/index.mjs.map +1 -1
- package/dist/manifests/accordion.manifest.json +2 -2
- package/dist/manifests/alert.manifest.json +1 -1
- package/dist/manifests/announcement-bar.manifest.json +1 -1
- package/dist/manifests/app-shell.manifest.json +1 -1
- package/dist/manifests/applied-filters.manifest.json +1 -1
- package/dist/manifests/article-card.manifest.json +1 -1
- package/dist/manifests/auth-layout.manifest.json +1 -1
- package/dist/manifests/autocomplete.manifest.json +1 -1
- package/dist/manifests/avatar.manifest.json +1 -1
- package/dist/manifests/badge.manifest.json +1 -1
- package/dist/manifests/block.manifest.json +1 -1
- package/dist/manifests/bottom-nav.manifest.json +1 -1
- package/dist/manifests/breadcrumb.manifest.json +1 -1
- package/dist/manifests/button-group.manifest.json +1 -1
- package/dist/manifests/button.manifest.json +1 -1
- package/dist/manifests/calendar.manifest.json +175 -0
- package/dist/manifests/card.manifest.json +1 -1
- package/dist/manifests/checkbox.manifest.json +1 -1
- package/dist/manifests/comparison-table.manifest.json +1 -1
- package/dist/manifests/confirm-dialog.manifest.json +1 -1
- package/dist/manifests/contact-strip.manifest.json +1 -1
- package/dist/manifests/container.manifest.json +1 -1
- package/dist/manifests/cta-section.manifest.json +1 -1
- package/dist/manifests/data-table.manifest.json +8 -1
- package/dist/manifests/date-picker-popover.manifest.json +202 -0
- package/dist/manifests/date-picker.manifest.json +1 -1
- package/dist/manifests/date-range-picker.manifest.json +1 -1
- package/dist/manifests/deal-card.manifest.json +1 -1
- package/dist/manifests/dialog.manifest.json +1 -1
- package/dist/manifests/document-card.manifest.json +1 -1
- package/dist/manifests/drawer.manifest.json +1 -1
- package/dist/manifests/empty-state.manifest.json +1 -1
- package/dist/manifests/entity-card.manifest.json +1 -1
- package/dist/manifests/feature-grid.manifest.json +1 -1
- package/dist/manifests/feature-row.manifest.json +1 -1
- package/dist/manifests/fieldset.manifest.json +1 -1
- package/dist/manifests/file-upload.manifest.json +1 -1
- package/dist/manifests/filter-bar.manifest.json +1 -1
- package/dist/manifests/filter-chips.manifest.json +13 -1
- package/dist/manifests/filter-panel.manifest.json +1 -1
- package/dist/manifests/flex.manifest.json +1 -1
- package/dist/manifests/form-field.manifest.json +1 -1
- package/dist/manifests/form-layout.manifest.json +1 -1
- package/dist/manifests/form.manifest.json +1 -1
- package/dist/manifests/grid.manifest.json +1 -1
- package/dist/manifests/heading.manifest.json +1 -1
- package/dist/manifests/hero.manifest.json +1 -1
- package/dist/manifests/image.manifest.json +142 -0
- package/dist/manifests/input-group.manifest.json +1 -1
- package/dist/manifests/input.manifest.json +1 -1
- package/dist/manifests/label.manifest.json +1 -1
- package/dist/manifests/link-tabs.manifest.json +1 -1
- package/dist/manifests/link.manifest.json +1 -1
- package/dist/manifests/list.manifest.json +1 -1
- package/dist/manifests/load-more.manifest.json +1 -1
- package/dist/manifests/logo-cloud.manifest.json +1 -1
- package/dist/manifests/menu.manifest.json +1 -1
- package/dist/manifests/metric-card.manifest.json +1 -1
- package/dist/manifests/multi-select.manifest.json +1 -1
- package/dist/manifests/newsletter.manifest.json +1 -1
- package/dist/manifests/page-header.manifest.json +1 -1
- package/dist/manifests/pagination.manifest.json +1 -1
- package/dist/manifests/password-input.manifest.json +1 -1
- package/dist/manifests/popover.manifest.json +86 -4
- package/dist/manifests/process-steps.manifest.json +1 -1
- package/dist/manifests/progress.manifest.json +1 -1
- package/dist/manifests/prose.manifest.json +1 -1
- package/dist/manifests/radio.manifest.json +1 -1
- package/dist/manifests/range-slider.manifest.json +1 -1
- package/dist/manifests/search.manifest.json +1 -1
- package/dist/manifests/section-heading.manifest.json +1 -1
- package/dist/manifests/section.manifest.json +1 -1
- package/dist/manifests/segmented-control.manifest.json +1 -1
- package/dist/manifests/select-menu.manifest.json +1 -1
- package/dist/manifests/select.manifest.json +8 -1
- package/dist/manifests/separator.manifest.json +1 -1
- package/dist/manifests/site-footer.manifest.json +1 -1
- package/dist/manifests/site-header.manifest.json +13 -3
- package/dist/manifests/skeleton.manifest.json +1 -1
- package/dist/manifests/spinner.manifest.json +1 -1
- package/dist/manifests/stat-band.manifest.json +1 -1
- package/dist/manifests/stepper.manifest.json +7 -1
- package/dist/manifests/switch.manifest.json +1 -1
- package/dist/manifests/table-card.manifest.json +1 -1
- package/dist/manifests/table-of-contents.manifest.json +1 -1
- package/dist/manifests/table.manifest.json +1 -1
- package/dist/manifests/tabs.manifest.json +1 -1
- package/dist/manifests/testimonial.manifest.json +1 -1
- package/dist/manifests/text.manifest.json +1 -1
- package/dist/manifests/textarea.manifest.json +1 -1
- package/dist/manifests/theme-toggle.manifest.json +1 -1
- package/dist/manifests/time-picker.manifest.json +1 -1
- package/dist/manifests/timeline.manifest.json +1 -1
- package/dist/manifests/toast.manifest.json +1 -1
- package/dist/manifests/tombstone-card.manifest.json +1 -1
- package/dist/manifests/tooltip.manifest.json +12 -1
- package/dist/src/components/accordion/Accordion.js +26 -19
- package/dist/src/components/accordion/Accordion.js.map +1 -1
- package/dist/src/components/accordion/Accordion.mjs +26 -19
- package/dist/src/components/accordion/Accordion.mjs.map +1 -1
- package/dist/src/components/alert/Alert.js +1 -1
- package/dist/src/components/alert/Alert.js.map +1 -1
- package/dist/src/components/alert/Alert.mjs +1 -1
- package/dist/src/components/alert/Alert.mjs.map +1 -1
- package/dist/src/components/app-shell/AppShell.js +1 -1
- package/dist/src/components/app-shell/AppShell.js.map +1 -1
- package/dist/src/components/app-shell/AppShell.mjs +1 -1
- package/dist/src/components/app-shell/AppShell.mjs.map +1 -1
- package/dist/src/components/article-card/ArticleCard.js +2 -2
- package/dist/src/components/article-card/ArticleCard.js.map +1 -1
- package/dist/src/components/article-card/ArticleCard.mjs +2 -2
- package/dist/src/components/article-card/ArticleCard.mjs.map +1 -1
- package/dist/src/components/calendar/Calendar.d.ts +34 -0
- package/dist/src/components/calendar/Calendar.js +233 -0
- package/dist/src/components/calendar/Calendar.js.map +1 -0
- package/dist/src/components/calendar/Calendar.mjs +208 -0
- package/dist/src/components/calendar/Calendar.mjs.map +1 -0
- package/dist/src/components/calendar/index.d.ts +1 -0
- package/dist/src/components/calendar/index.js +23 -0
- package/dist/src/components/calendar/index.js.map +1 -0
- package/dist/src/components/calendar/index.mjs +2 -0
- package/dist/src/components/calendar/index.mjs.map +1 -0
- package/dist/src/components/checkbox/Checkbox.js +1 -1
- package/dist/src/components/checkbox/Checkbox.js.map +1 -1
- package/dist/src/components/checkbox/Checkbox.mjs +1 -1
- package/dist/src/components/checkbox/Checkbox.mjs.map +1 -1
- package/dist/src/components/comparison-table/ComparisonTable.js +1 -1
- package/dist/src/components/comparison-table/ComparisonTable.js.map +1 -1
- package/dist/src/components/comparison-table/ComparisonTable.mjs +1 -1
- package/dist/src/components/comparison-table/ComparisonTable.mjs.map +1 -1
- package/dist/src/components/cta-section/CTASection.js +1 -1
- package/dist/src/components/cta-section/CTASection.js.map +1 -1
- package/dist/src/components/cta-section/CTASection.mjs +1 -1
- package/dist/src/components/cta-section/CTASection.mjs.map +1 -1
- package/dist/src/components/data-table/DataTable.d.ts +3 -1
- package/dist/src/components/data-table/DataTable.js +2 -4
- package/dist/src/components/data-table/DataTable.js.map +1 -1
- package/dist/src/components/data-table/DataTable.mjs +2 -4
- package/dist/src/components/data-table/DataTable.mjs.map +1 -1
- package/dist/src/components/date-picker-popover/DatePickerPopover.d.ts +33 -0
- package/dist/src/components/date-picker-popover/DatePickerPopover.js +117 -0
- package/dist/src/components/date-picker-popover/DatePickerPopover.js.map +1 -0
- package/dist/src/components/date-picker-popover/DatePickerPopover.mjs +83 -0
- package/dist/src/components/date-picker-popover/DatePickerPopover.mjs.map +1 -0
- package/dist/src/components/date-picker-popover/index.d.ts +1 -0
- package/dist/src/components/date-picker-popover/index.js +23 -0
- package/dist/src/components/date-picker-popover/index.js.map +1 -0
- package/dist/src/components/date-picker-popover/index.mjs +2 -0
- package/dist/src/components/date-picker-popover/index.mjs.map +1 -0
- package/dist/src/components/drawer/Drawer.js +2 -1
- package/dist/src/components/drawer/Drawer.js.map +1 -1
- package/dist/src/components/drawer/Drawer.mjs +2 -1
- package/dist/src/components/drawer/Drawer.mjs.map +1 -1
- package/dist/src/components/filter-chips/FilterChips.d.ts +4 -0
- package/dist/src/components/filter-chips/FilterChips.js +35 -4
- package/dist/src/components/filter-chips/FilterChips.js.map +1 -1
- package/dist/src/components/filter-chips/FilterChips.mjs +35 -4
- package/dist/src/components/filter-chips/FilterChips.mjs.map +1 -1
- package/dist/src/components/image/Image.d.ts +34 -0
- package/dist/src/components/image/Image.js +75 -0
- package/dist/src/components/image/Image.js.map +1 -0
- package/dist/src/components/image/Image.mjs +41 -0
- package/dist/src/components/image/Image.mjs.map +1 -0
- package/dist/src/components/image/index.d.ts +1 -0
- package/dist/src/components/image/index.js +29 -0
- package/dist/src/components/image/index.js.map +1 -0
- package/dist/src/components/image/index.mjs +5 -0
- package/dist/src/components/image/index.mjs.map +1 -0
- package/dist/src/components/link/Link.js +4 -4
- package/dist/src/components/link/Link.js.map +1 -1
- package/dist/src/components/link/Link.mjs +4 -4
- package/dist/src/components/link/Link.mjs.map +1 -1
- package/dist/src/components/page-header/PageHeader.js +1 -1
- package/dist/src/components/page-header/PageHeader.js.map +1 -1
- package/dist/src/components/page-header/PageHeader.mjs +1 -1
- package/dist/src/components/page-header/PageHeader.mjs.map +1 -1
- package/dist/src/components/popover/Popover.d.ts +36 -3
- package/dist/src/components/popover/Popover.js +118 -22
- package/dist/src/components/popover/Popover.js.map +1 -1
- package/dist/src/components/popover/Popover.mjs +117 -22
- package/dist/src/components/popover/Popover.mjs.map +1 -1
- package/dist/src/components/radio/Radio.js +1 -1
- package/dist/src/components/radio/Radio.js.map +1 -1
- package/dist/src/components/radio/Radio.mjs +1 -1
- package/dist/src/components/radio/Radio.mjs.map +1 -1
- package/dist/src/components/range-slider/RangeSlider.js +3 -3
- package/dist/src/components/range-slider/RangeSlider.js.map +1 -1
- package/dist/src/components/range-slider/RangeSlider.mjs +3 -3
- package/dist/src/components/range-slider/RangeSlider.mjs.map +1 -1
- package/dist/src/components/section-heading/SectionHeading.js +1 -1
- package/dist/src/components/section-heading/SectionHeading.js.map +1 -1
- package/dist/src/components/section-heading/SectionHeading.mjs +1 -1
- package/dist/src/components/section-heading/SectionHeading.mjs.map +1 -1
- package/dist/src/components/select/Select.d.ts +10 -0
- package/dist/src/components/select/Select.js +2 -2
- package/dist/src/components/select/Select.js.map +1 -1
- package/dist/src/components/select/Select.mjs +2 -2
- package/dist/src/components/select/Select.mjs.map +1 -1
- package/dist/src/components/site-header/SiteHeader.d.ts +25 -3
- package/dist/src/components/site-header/SiteHeader.js +141 -6
- package/dist/src/components/site-header/SiteHeader.js.map +1 -1
- package/dist/src/components/site-header/SiteHeader.mjs +141 -6
- package/dist/src/components/site-header/SiteHeader.mjs.map +1 -1
- package/dist/src/components/stepper/Stepper.d.ts +18 -0
- package/dist/src/components/stepper/Stepper.js +2 -1
- package/dist/src/components/stepper/Stepper.js.map +1 -1
- package/dist/src/components/stepper/Stepper.mjs +2 -1
- package/dist/src/components/stepper/Stepper.mjs.map +1 -1
- package/dist/src/components/timeline/Timeline.js +17 -13
- package/dist/src/components/timeline/Timeline.js.map +1 -1
- package/dist/src/components/timeline/Timeline.mjs +17 -13
- package/dist/src/components/timeline/Timeline.mjs.map +1 -1
- package/dist/src/components/tooltip/Tooltip.d.ts +5 -0
- package/dist/src/components/tooltip/Tooltip.js +9 -2
- package/dist/src/components/tooltip/Tooltip.js.map +1 -1
- package/dist/src/components/tooltip/Tooltip.mjs +9 -2
- package/dist/src/components/tooltip/Tooltip.mjs.map +1 -1
- package/dist/src/index.d.ts +3 -0
- package/dist/src/utils/date.d.ts +32 -0
- package/dist/src/utils/date.js +171 -0
- package/dist/src/utils/date.js.map +1 -0
- package/dist/src/utils/date.mjs +134 -0
- package/dist/src/utils/date.mjs.map +1 -0
- package/dist/src/utils/position.d.ts +42 -0
- package/dist/src/utils/position.js +91 -0
- package/dist/src/utils/position.js.map +1 -0
- package/dist/src/utils/position.mjs +67 -0
- package/dist/src/utils/position.mjs.map +1 -0
- package/dist/styles-full.css +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/components/accordion/Accordion.test.tsx +14 -3
- package/src/components/accordion/Accordion.tsx +34 -21
- package/src/components/alert/Alert.tsx +1 -1
- package/src/components/app-shell/AppShell.tsx +1 -1
- package/src/components/article-card/ArticleCard.tsx +2 -2
- package/src/components/calendar/Calendar.test.tsx +277 -0
- package/src/components/calendar/Calendar.tsx +273 -0
- package/src/components/calendar/index.ts +1 -0
- package/src/components/checkbox/Checkbox.tsx +1 -1
- package/src/components/comparison-table/ComparisonTable.tsx +1 -1
- package/src/components/cta-section/CTASection.tsx +1 -1
- package/src/components/data-table/DataTable.test.tsx +21 -0
- package/src/components/data-table/DataTable.tsx +4 -1
- package/src/components/date-picker-popover/DatePickerPopover.test.tsx +223 -0
- package/src/components/date-picker-popover/DatePickerPopover.tsx +117 -0
- package/src/components/date-picker-popover/index.ts +1 -0
- package/src/components/drawer/Drawer.test.tsx +12 -0
- package/src/components/drawer/Drawer.tsx +8 -1
- package/src/components/filter-chips/FilterChips.test.tsx +11 -0
- package/src/components/filter-chips/FilterChips.tsx +40 -4
- package/src/components/image/Image.test.tsx +94 -0
- package/src/components/image/Image.tsx +71 -0
- package/src/components/image/index.ts +1 -0
- package/src/components/link/Link.test.tsx +2 -1
- package/src/components/link/Link.tsx +4 -4
- package/src/components/page-header/PageHeader.tsx +1 -1
- package/src/components/popover/Popover.test.tsx +307 -3
- package/src/components/popover/Popover.tsx +228 -91
- package/src/components/radio/Radio.tsx +1 -1
- package/src/components/range-slider/RangeSlider.tsx +3 -3
- package/src/components/section-heading/SectionHeading.tsx +1 -1
- package/src/components/select/Select.test.tsx +14 -0
- package/src/components/select/Select.tsx +7 -2
- package/src/components/site-header/SiteHeader.test.tsx +103 -1
- package/src/components/site-header/SiteHeader.tsx +220 -16
- package/src/components/stepper/Stepper.test.tsx +12 -0
- package/src/components/stepper/Stepper.tsx +15 -1
- package/src/components/timeline/Timeline.test.tsx +11 -0
- package/src/components/timeline/Timeline.tsx +13 -2
- package/src/components/tooltip/Tooltip.test.tsx +15 -0
- package/src/components/tooltip/Tooltip.tsx +19 -2
- package/src/index.ts +3 -0
- package/src/manifests/accordion.manifest.json +2 -2
- package/src/manifests/alert.manifest.json +1 -1
- package/src/manifests/announcement-bar.manifest.json +1 -1
- package/src/manifests/app-shell.manifest.json +1 -1
- package/src/manifests/applied-filters.manifest.json +1 -1
- package/src/manifests/article-card.manifest.json +1 -1
- package/src/manifests/auth-layout.manifest.json +1 -1
- package/src/manifests/autocomplete.manifest.json +1 -1
- package/src/manifests/avatar.manifest.json +1 -1
- package/src/manifests/badge.manifest.json +1 -1
- package/src/manifests/block.manifest.json +1 -1
- package/src/manifests/bottom-nav.manifest.json +1 -1
- package/src/manifests/breadcrumb.manifest.json +1 -1
- package/src/manifests/button-group.manifest.json +1 -1
- package/src/manifests/button.manifest.json +1 -1
- package/src/manifests/calendar.manifest.json +175 -0
- package/src/manifests/card.manifest.json +1 -1
- package/src/manifests/checkbox.manifest.json +1 -1
- package/src/manifests/comparison-table.manifest.json +1 -1
- package/src/manifests/confirm-dialog.manifest.json +1 -1
- package/src/manifests/contact-strip.manifest.json +1 -1
- package/src/manifests/container.manifest.json +1 -1
- package/src/manifests/cta-section.manifest.json +1 -1
- package/src/manifests/data-table.manifest.json +8 -1
- package/src/manifests/date-picker-popover.manifest.json +202 -0
- package/src/manifests/date-picker.manifest.json +1 -1
- package/src/manifests/date-range-picker.manifest.json +1 -1
- package/src/manifests/deal-card.manifest.json +1 -1
- package/src/manifests/dialog.manifest.json +1 -1
- package/src/manifests/document-card.manifest.json +1 -1
- package/src/manifests/drawer.manifest.json +1 -1
- package/src/manifests/empty-state.manifest.json +1 -1
- package/src/manifests/entity-card.manifest.json +1 -1
- package/src/manifests/feature-grid.manifest.json +1 -1
- package/src/manifests/feature-row.manifest.json +1 -1
- package/src/manifests/fieldset.manifest.json +1 -1
- package/src/manifests/file-upload.manifest.json +1 -1
- package/src/manifests/filter-bar.manifest.json +1 -1
- package/src/manifests/filter-chips.manifest.json +13 -1
- package/src/manifests/filter-panel.manifest.json +1 -1
- package/src/manifests/flex.manifest.json +1 -1
- package/src/manifests/form-field.manifest.json +1 -1
- package/src/manifests/form-layout.manifest.json +1 -1
- package/src/manifests/form.manifest.json +1 -1
- package/src/manifests/grid.manifest.json +1 -1
- package/src/manifests/heading.manifest.json +1 -1
- package/src/manifests/hero.manifest.json +1 -1
- package/src/manifests/image.manifest.json +142 -0
- package/src/manifests/input-group.manifest.json +1 -1
- package/src/manifests/input.manifest.json +1 -1
- package/src/manifests/label.manifest.json +1 -1
- package/src/manifests/link-tabs.manifest.json +1 -1
- package/src/manifests/link.manifest.json +1 -1
- package/src/manifests/list.manifest.json +1 -1
- package/src/manifests/load-more.manifest.json +1 -1
- package/src/manifests/logo-cloud.manifest.json +1 -1
- package/src/manifests/menu.manifest.json +1 -1
- package/src/manifests/metric-card.manifest.json +1 -1
- package/src/manifests/multi-select.manifest.json +1 -1
- package/src/manifests/newsletter.manifest.json +1 -1
- package/src/manifests/page-header.manifest.json +1 -1
- package/src/manifests/pagination.manifest.json +1 -1
- package/src/manifests/password-input.manifest.json +1 -1
- package/src/manifests/popover.manifest.json +86 -4
- package/src/manifests/process-steps.manifest.json +1 -1
- package/src/manifests/progress.manifest.json +1 -1
- package/src/manifests/prose.manifest.json +1 -1
- package/src/manifests/radio.manifest.json +1 -1
- package/src/manifests/range-slider.manifest.json +1 -1
- package/src/manifests/search.manifest.json +1 -1
- package/src/manifests/section-heading.manifest.json +1 -1
- package/src/manifests/section.manifest.json +1 -1
- package/src/manifests/segmented-control.manifest.json +1 -1
- package/src/manifests/select-menu.manifest.json +1 -1
- package/src/manifests/select.manifest.json +8 -1
- package/src/manifests/separator.manifest.json +1 -1
- package/src/manifests/site-footer.manifest.json +1 -1
- package/src/manifests/site-header.manifest.json +13 -3
- package/src/manifests/skeleton.manifest.json +1 -1
- package/src/manifests/spinner.manifest.json +1 -1
- package/src/manifests/stat-band.manifest.json +1 -1
- package/src/manifests/stepper.manifest.json +7 -1
- package/src/manifests/switch.manifest.json +1 -1
- package/src/manifests/table-card.manifest.json +1 -1
- package/src/manifests/table-of-contents.manifest.json +1 -1
- package/src/manifests/table.manifest.json +1 -1
- package/src/manifests/tabs.manifest.json +1 -1
- package/src/manifests/testimonial.manifest.json +1 -1
- package/src/manifests/text.manifest.json +1 -1
- package/src/manifests/textarea.manifest.json +1 -1
- package/src/manifests/theme-toggle.manifest.json +1 -1
- package/src/manifests/time-picker.manifest.json +1 -1
- package/src/manifests/timeline.manifest.json +1 -1
- package/src/manifests/toast.manifest.json +1 -1
- package/src/manifests/tombstone-card.manifest.json +1 -1
- package/src/manifests/tooltip.manifest.json +12 -1
- package/src/utils/date.test.ts +190 -0
- package/src/utils/date.ts +162 -0
- package/src/utils/position.test.ts +227 -0
- package/src/utils/position.ts +129 -0
|
@@ -3,14 +3,19 @@
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { createPortal } from 'react-dom';
|
|
5
5
|
import { cn } from '../../utils/cn';
|
|
6
|
+
import { computePosition, type Align, type PositionResult, type Side } from '../../utils/position';
|
|
6
7
|
|
|
7
8
|
type PopoverContextValue = {
|
|
8
9
|
open: boolean;
|
|
9
10
|
setOpen: (open: boolean) => void;
|
|
10
11
|
triggerId: string;
|
|
11
12
|
contentId: string;
|
|
12
|
-
/** The relative wrapper the popover is anchored to
|
|
13
|
+
/** The relative wrapper the popover is anchored to by default. */
|
|
13
14
|
wrapperRef: React.MutableRefObject<HTMLDivElement | null>;
|
|
15
|
+
/** Optional explicit anchor, rendered by PopoverAnchor. */
|
|
16
|
+
anchorRef: React.MutableRefObject<HTMLElement | null>;
|
|
17
|
+
/** The rendered trigger, so Escape can restore focus and labels stay valid. */
|
|
18
|
+
triggerRef: React.MutableRefObject<HTMLButtonElement | null>;
|
|
14
19
|
};
|
|
15
20
|
|
|
16
21
|
const PopoverContext = React.createContext<PopoverContextValue>({
|
|
@@ -19,6 +24,8 @@ const PopoverContext = React.createContext<PopoverContextValue>({
|
|
|
19
24
|
triggerId: '',
|
|
20
25
|
contentId: '',
|
|
21
26
|
wrapperRef: { current: null },
|
|
27
|
+
anchorRef: { current: null },
|
|
28
|
+
triggerRef: { current: null },
|
|
22
29
|
});
|
|
23
30
|
|
|
24
31
|
export type PopoverProps = {
|
|
@@ -42,6 +49,8 @@ const Popover = React.forwardRef<HTMLDivElement, PopoverProps>(
|
|
|
42
49
|
const triggerId = React.useId();
|
|
43
50
|
const contentId = React.useId();
|
|
44
51
|
const wrapperRef = React.useRef<HTMLDivElement | null>(null);
|
|
52
|
+
const anchorRef = React.useRef<HTMLElement | null>(null);
|
|
53
|
+
const triggerRef = React.useRef<HTMLButtonElement | null>(null);
|
|
45
54
|
const setRefs = React.useCallback(
|
|
46
55
|
(node: HTMLDivElement | null) => {
|
|
47
56
|
wrapperRef.current = node;
|
|
@@ -62,7 +71,7 @@ const Popover = React.forwardRef<HTMLDivElement, PopoverProps>(
|
|
|
62
71
|
return (
|
|
63
72
|
<div ref={setRefs} className={cn('relative inline-block', className)}>
|
|
64
73
|
<PopoverContext.Provider
|
|
65
|
-
value={{ open: current, setOpen, triggerId, contentId, wrapperRef }}
|
|
74
|
+
value={{ open: current, setOpen, triggerId, contentId, wrapperRef, anchorRef, triggerRef }}
|
|
66
75
|
>
|
|
67
76
|
{children}
|
|
68
77
|
</PopoverContext.Provider>
|
|
@@ -76,12 +85,20 @@ export type PopoverTriggerProps = React.ButtonHTMLAttributes<HTMLButtonElement>;
|
|
|
76
85
|
|
|
77
86
|
/** The button that toggles the popover. */
|
|
78
87
|
const PopoverTrigger = React.forwardRef<HTMLButtonElement, PopoverTriggerProps>(
|
|
79
|
-
({ className, children, onClick, ...props }, ref) => {
|
|
80
|
-
const { open, setOpen, triggerId, contentId } = React.useContext(PopoverContext);
|
|
88
|
+
({ className, children, onClick, id, ...props }, ref) => {
|
|
89
|
+
const { open, setOpen, triggerId, contentId, triggerRef } = React.useContext(PopoverContext);
|
|
90
|
+
const setRefs = React.useCallback(
|
|
91
|
+
(node: HTMLButtonElement | null) => {
|
|
92
|
+
triggerRef.current = node;
|
|
93
|
+
if (typeof ref === 'function') ref(node);
|
|
94
|
+
else if (ref) ref.current = node;
|
|
95
|
+
},
|
|
96
|
+
[ref, triggerRef]
|
|
97
|
+
);
|
|
81
98
|
return (
|
|
82
99
|
<button
|
|
83
|
-
ref={
|
|
84
|
-
id={triggerId}
|
|
100
|
+
ref={setRefs}
|
|
101
|
+
id={id ?? triggerId}
|
|
85
102
|
type="button"
|
|
86
103
|
aria-haspopup="dialog"
|
|
87
104
|
aria-expanded={open}
|
|
@@ -104,91 +121,211 @@ const PopoverTrigger = React.forwardRef<HTMLButtonElement, PopoverTriggerProps>(
|
|
|
104
121
|
);
|
|
105
122
|
PopoverTrigger.displayName = 'PopoverTrigger';
|
|
106
123
|
|
|
107
|
-
export type
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
124
|
+
export type PopoverAnchorProps = React.HTMLAttributes<HTMLSpanElement>;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Anchors the panel to this element instead of the trigger. Useful when the
|
|
128
|
+
* panel belongs to a field that is not itself the button opening it.
|
|
129
|
+
*/
|
|
130
|
+
const PopoverAnchor = React.forwardRef<HTMLSpanElement, PopoverAnchorProps>(
|
|
131
|
+
({ className, children, ...props }, ref) => {
|
|
132
|
+
const { anchorRef } = React.useContext(PopoverContext);
|
|
133
|
+
const setRefs = React.useCallback(
|
|
134
|
+
(node: HTMLSpanElement | null) => {
|
|
135
|
+
anchorRef.current = node;
|
|
136
|
+
if (typeof ref === 'function') ref(node);
|
|
137
|
+
else if (ref) ref.current = node;
|
|
138
|
+
},
|
|
139
|
+
[anchorRef, ref]
|
|
140
|
+
);
|
|
141
|
+
return (
|
|
142
|
+
<span ref={setRefs} className={cn('inline-block', className)} {...props}>
|
|
143
|
+
{children}
|
|
144
|
+
</span>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
PopoverAnchor.displayName = 'PopoverAnchor';
|
|
149
|
+
|
|
150
|
+
export type PopoverContentProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
151
|
+
/** Preferred side of the anchor. Flips when it cannot fit. */
|
|
152
|
+
side?: Side;
|
|
153
|
+
/** Cross-axis alignment against the anchor. */
|
|
154
|
+
align?: Align;
|
|
155
|
+
/** Gap between anchor and panel. */
|
|
156
|
+
sideOffset?: number;
|
|
157
|
+
/** Nudge along the cross axis. */
|
|
158
|
+
alignOffset?: number;
|
|
159
|
+
/** Minimum distance kept from the viewport edges. */
|
|
160
|
+
collisionPadding?: number;
|
|
161
|
+
/** Match the panel width to the anchor width (select-like panels). */
|
|
162
|
+
matchTriggerWidth?: boolean;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
function rectOf(element: Element) {
|
|
166
|
+
const rect = element.getBoundingClientRect();
|
|
167
|
+
return {
|
|
168
|
+
top: rect.top,
|
|
169
|
+
left: rect.left,
|
|
170
|
+
width: rect.width || (element as HTMLElement).offsetWidth || 0,
|
|
171
|
+
height: rect.height || (element as HTMLElement).offsetHeight || 0,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** The floating panel with interactive content. */
|
|
176
|
+
const PopoverContent = React.forwardRef<HTMLDivElement, PopoverContentProps>(
|
|
177
|
+
(
|
|
178
|
+
{
|
|
179
|
+
className,
|
|
180
|
+
children,
|
|
181
|
+
onKeyDown,
|
|
182
|
+
style,
|
|
183
|
+
side = 'bottom',
|
|
184
|
+
align = 'start',
|
|
185
|
+
sideOffset = 8,
|
|
186
|
+
alignOffset = 0,
|
|
187
|
+
collisionPadding = 8,
|
|
188
|
+
matchTriggerWidth = false,
|
|
189
|
+
...props
|
|
190
|
+
},
|
|
191
|
+
ref
|
|
192
|
+
) => {
|
|
193
|
+
const { open, setOpen, contentId, wrapperRef, anchorRef, triggerRef } =
|
|
194
|
+
React.useContext(PopoverContext);
|
|
195
|
+
// The trigger may carry a consumer `id`; read the rendered element so the
|
|
196
|
+
// dialog's label always points at something that exists.
|
|
197
|
+
const labelledBy = triggerRef.current?.id || undefined;
|
|
198
|
+
const contentRef = React.useRef<HTMLDivElement | null>(null);
|
|
199
|
+
// Viewport coordinates measured from the anchor; the panel portals to
|
|
200
|
+
// document.body with position:fixed so ancestor overflow can never clip it.
|
|
201
|
+
const [pos, setPos] = React.useState<PositionResult | null>(null);
|
|
202
|
+
const [width, setWidth] = React.useState<number | undefined>(undefined);
|
|
203
|
+
|
|
204
|
+
const updatePosition = React.useCallback(() => {
|
|
205
|
+
const anchorEl = anchorRef.current ?? wrapperRef.current;
|
|
206
|
+
const panel = contentRef.current;
|
|
207
|
+
if (!anchorEl || !panel) return;
|
|
208
|
+
const anchor = rectOf(anchorEl);
|
|
209
|
+
const measured = rectOf(panel);
|
|
210
|
+
setWidth(matchTriggerWidth ? anchor.width : undefined);
|
|
211
|
+
setPos(
|
|
212
|
+
computePosition({
|
|
213
|
+
anchor,
|
|
214
|
+
content: { width: measured.width, height: measured.height },
|
|
215
|
+
viewport: { width: window.innerWidth, height: window.innerHeight },
|
|
216
|
+
side,
|
|
217
|
+
align,
|
|
218
|
+
sideOffset,
|
|
219
|
+
alignOffset,
|
|
220
|
+
collisionPadding,
|
|
221
|
+
})
|
|
189
222
|
);
|
|
190
|
-
}
|
|
191
|
-
|
|
223
|
+
}, [
|
|
224
|
+
align,
|
|
225
|
+
alignOffset,
|
|
226
|
+
anchorRef,
|
|
227
|
+
collisionPadding,
|
|
228
|
+
matchTriggerWidth,
|
|
229
|
+
side,
|
|
230
|
+
sideOffset,
|
|
231
|
+
wrapperRef,
|
|
232
|
+
]);
|
|
233
|
+
|
|
234
|
+
React.useLayoutEffect(() => {
|
|
235
|
+
if (!open) {
|
|
236
|
+
setPos(null);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
updatePosition();
|
|
240
|
+
}, [open, updatePosition]);
|
|
241
|
+
|
|
242
|
+
// A panel that is already open on first mount measures before the wrapper's
|
|
243
|
+
// ref is attached (child layout effects run first), so measure once more
|
|
244
|
+
// when the refs exist.
|
|
245
|
+
React.useEffect(() => {
|
|
246
|
+
if (open && !pos) updatePosition();
|
|
247
|
+
}, [open, pos, updatePosition]);
|
|
248
|
+
|
|
249
|
+
// Keep the panel anchored while the page moves: reposition on scroll and
|
|
250
|
+
// resize, and re-measure when the content itself changes size.
|
|
251
|
+
React.useEffect(() => {
|
|
252
|
+
if (!open) return;
|
|
253
|
+
const onScroll = () => updatePosition();
|
|
254
|
+
window.addEventListener('scroll', onScroll, true);
|
|
255
|
+
window.addEventListener('resize', onScroll);
|
|
256
|
+
const panel = contentRef.current;
|
|
257
|
+
const observer =
|
|
258
|
+
typeof ResizeObserver === 'undefined' || !panel ? null : new ResizeObserver(onScroll);
|
|
259
|
+
if (panel && observer) observer.observe(panel);
|
|
260
|
+
return () => {
|
|
261
|
+
window.removeEventListener('scroll', onScroll, true);
|
|
262
|
+
window.removeEventListener('resize', onScroll);
|
|
263
|
+
observer?.disconnect();
|
|
264
|
+
};
|
|
265
|
+
}, [open, updatePosition]);
|
|
266
|
+
|
|
267
|
+
// Close on outside click.
|
|
268
|
+
React.useEffect(() => {
|
|
269
|
+
if (!open) return;
|
|
270
|
+
function onPointerDown(event: PointerEvent) {
|
|
271
|
+
if (!contentRef.current?.contains(event.target as Node)) setOpen(false);
|
|
272
|
+
}
|
|
273
|
+
document.addEventListener('pointerdown', onPointerDown);
|
|
274
|
+
return () => document.removeEventListener('pointerdown', onPointerDown);
|
|
275
|
+
}, [open, setOpen]);
|
|
276
|
+
|
|
277
|
+
// Focus the content when it opens so Escape reaches it. Depends on `pos`
|
|
278
|
+
// because the panel only mounts once measured.
|
|
279
|
+
React.useEffect(() => {
|
|
280
|
+
if (open && pos && contentRef.current) {
|
|
281
|
+
contentRef.current.focus();
|
|
282
|
+
}
|
|
283
|
+
}, [open, pos]);
|
|
284
|
+
|
|
285
|
+
if (!open || typeof document === 'undefined') return null;
|
|
286
|
+
|
|
287
|
+
return createPortal(
|
|
288
|
+
<div
|
|
289
|
+
ref={(node) => {
|
|
290
|
+
contentRef.current = node;
|
|
291
|
+
if (typeof ref === 'function') ref(node);
|
|
292
|
+
else if (ref) ref.current = node;
|
|
293
|
+
}}
|
|
294
|
+
id={contentId}
|
|
295
|
+
role="dialog"
|
|
296
|
+
aria-labelledby={labelledBy}
|
|
297
|
+
tabIndex={-1}
|
|
298
|
+
data-side={pos?.side ?? side}
|
|
299
|
+
onKeyDown={(event) => {
|
|
300
|
+
onKeyDown?.(event);
|
|
301
|
+
if (event.key === 'Escape') {
|
|
302
|
+
event.stopPropagation();
|
|
303
|
+
setOpen(false);
|
|
304
|
+
// Escape must hand focus back, or it lands on <body>.
|
|
305
|
+
(triggerRef.current ?? anchorRef.current)?.focus();
|
|
306
|
+
}
|
|
307
|
+
}}
|
|
308
|
+
style={{
|
|
309
|
+
position: 'fixed',
|
|
310
|
+
top: pos?.top ?? 0,
|
|
311
|
+
left: pos?.left ?? 0,
|
|
312
|
+
width,
|
|
313
|
+
visibility: pos ? 'visible' : 'hidden',
|
|
314
|
+
zIndex: 50,
|
|
315
|
+
...style,
|
|
316
|
+
}}
|
|
317
|
+
className={cn(
|
|
318
|
+
'w-72 rounded-md border border-border bg-popover p-4 text-popover-foreground shadow-md outline-none',
|
|
319
|
+
className
|
|
320
|
+
)}
|
|
321
|
+
{...props}
|
|
322
|
+
>
|
|
323
|
+
{children}
|
|
324
|
+
</div>,
|
|
325
|
+
document.body
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
);
|
|
192
329
|
PopoverContent.displayName = 'PopoverContent';
|
|
193
330
|
|
|
194
|
-
export { Popover,
|
|
331
|
+
export { Popover, PopoverAnchor, PopoverContent, PopoverTrigger };
|
|
@@ -26,7 +26,7 @@ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
|
|
|
26
26
|
onChange?.(event);
|
|
27
27
|
}}
|
|
28
28
|
className={cn(
|
|
29
|
-
'h-4 w-4 shrink-0 rounded-full border border-primary',
|
|
29
|
+
'h-4 w-4 shrink-0 rounded-full border border-primary accent-primary',
|
|
30
30
|
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
|
|
31
31
|
'disabled:cursor-not-allowed disabled:opacity-50',
|
|
32
32
|
'checked:bg-primary checked:text-primary-foreground',
|
|
@@ -34,9 +34,9 @@ export type RangeSliderProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'onCha
|
|
|
34
34
|
const rangeInputClass = cn(
|
|
35
35
|
'pointer-events-none absolute inset-x-0 top-1/2 h-6 w-full -translate-y-1/2 appearance-none bg-transparent',
|
|
36
36
|
'[&::-webkit-slider-runnable-track]:h-1 [&::-webkit-slider-runnable-track]:rounded-full [&::-webkit-slider-runnable-track]:bg-transparent',
|
|
37
|
-
'[&::-webkit-slider-thumb]:pointer-events-auto [&::-webkit-slider-thumb]:mt-[-6px] [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:cursor-grab [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:border-2 [&::-webkit-slider-thumb]:border-
|
|
37
|
+
'[&::-webkit-slider-thumb]:pointer-events-auto [&::-webkit-slider-thumb]:mt-[-6px] [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:cursor-grab [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:border-2 [&::-webkit-slider-thumb]:border-background [&::-webkit-slider-thumb]:bg-primary [&::-webkit-slider-thumb]:shadow-md',
|
|
38
38
|
'[&::-moz-range-track]:h-1 [&::-moz-range-track]:rounded-full [&::-moz-range-track]:bg-transparent',
|
|
39
|
-
'[&::-moz-range-thumb]:pointer-events-auto [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:cursor-grab [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-2 [&::-moz-range-thumb]:border-
|
|
39
|
+
'[&::-moz-range-thumb]:pointer-events-auto [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:cursor-grab [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-2 [&::-moz-range-thumb]:border-background [&::-moz-range-thumb]:bg-primary [&::-moz-range-thumb]:shadow-md',
|
|
40
40
|
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
|
|
41
41
|
'disabled:cursor-not-allowed disabled:opacity-50'
|
|
42
42
|
);
|
|
@@ -92,7 +92,7 @@ export const RangeSlider = React.forwardRef<HTMLDivElement, RangeSliderProps>(fu
|
|
|
92
92
|
</div>
|
|
93
93
|
)}
|
|
94
94
|
<div className="relative h-6 w-full">
|
|
95
|
-
<div className="absolute inset-x-0 top-1/2 h-1 -translate-y-1/2 rounded-full bg-
|
|
95
|
+
<div className="absolute inset-x-0 top-1/2 h-1 -translate-y-1/2 rounded-full bg-border" />
|
|
96
96
|
<div
|
|
97
97
|
className="absolute top-1/2 h-1 -translate-y-1/2 rounded-full bg-primary"
|
|
98
98
|
style={{ left: `${lowPercent}%`, right: `${100 - highPercent}%` }}
|
|
@@ -48,7 +48,7 @@ export const SectionHeading = React.forwardRef<HTMLDivElement, SectionHeadingPro
|
|
|
48
48
|
{...props}
|
|
49
49
|
>
|
|
50
50
|
<div className={cn('min-w-0', align === 'center' && 'flex flex-col items-center')}>
|
|
51
|
-
{eyebrow && <div className={cn('mb-1 text-xs font-medium uppercase tracking-wide text-primary', eyebrowClassName)}>{eyebrow}</div>}
|
|
51
|
+
{eyebrow && <div className={cn('mb-1 text-xs font-medium uppercase tracking-wide text-primary-ink', eyebrowClassName)}>{eyebrow}</div>}
|
|
52
52
|
<Heading className={cn('font-semibold tracking-tight', sizeClasses[size], titleClassName)}>{title}</Heading>
|
|
53
53
|
{description && (
|
|
54
54
|
<p className={cn('mt-2 max-w-2xl text-muted-foreground', align === 'center' ? 'mx-auto' : '', descriptionClassName)}>{description}</p>
|
|
@@ -20,6 +20,20 @@ describe('Select', () => {
|
|
|
20
20
|
expect(select).toBeInTheDocument();
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
+
it('can hide the label visually while keeping it accessible', () => {
|
|
24
|
+
render(
|
|
25
|
+
<Select
|
|
26
|
+
label="Status"
|
|
27
|
+
labelHidden
|
|
28
|
+
options={[{ value: 'all', label: 'All' }]}
|
|
29
|
+
defaultValue="all"
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
const label = screen.getByText('Status');
|
|
33
|
+
expect(label).toHaveClass('sr-only');
|
|
34
|
+
expect(screen.getByRole('combobox', { name: 'Status' })).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
|
|
23
37
|
it('supports uncontrolled defaultValue', () => {
|
|
24
38
|
render(<Select options={options} defaultValue="sm" aria-label="Size" />);
|
|
25
39
|
expect(screen.getByRole('combobox', { name: 'Size' })).toHaveValue('sm');
|
|
@@ -23,6 +23,11 @@ export type SelectProps = Omit<
|
|
|
23
23
|
/** Optgroups with a heading per section. Takes precedence over `options` and `children`. */
|
|
24
24
|
groups?: SelectOptionGroup[];
|
|
25
25
|
label?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Keep the label for assistive tech but hide it visually, so the control
|
|
28
|
+
* lines up with sibling inputs in a filter bar or toolbar.
|
|
29
|
+
*/
|
|
30
|
+
labelHidden?: boolean;
|
|
26
31
|
/** Renders a disabled empty option — the native "choose one" affordance. */
|
|
27
32
|
placeholder?: string;
|
|
28
33
|
/** Native multi-select: value/onChange switch to string[]. */
|
|
@@ -43,7 +48,7 @@ export type SelectProps = Omit<
|
|
|
43
48
|
* <option>/<optgroup> children for dynamic lists.
|
|
44
49
|
*/
|
|
45
50
|
export const Select = React.forwardRef<HTMLSelectElement, SelectProps>(function Select(
|
|
46
|
-
{ options, groups, label, placeholder, multiple = false, value, defaultValue, onChange, onValueChange, children, id, className, ...props },
|
|
51
|
+
{ options, groups, label, labelHidden = false, placeholder, multiple = false, value, defaultValue, onChange, onValueChange, children, id, className, ...props },
|
|
47
52
|
ref,
|
|
48
53
|
) {
|
|
49
54
|
const generatedId = React.useId();
|
|
@@ -59,7 +64,7 @@ export const Select = React.forwardRef<HTMLSelectElement, SelectProps>(function
|
|
|
59
64
|
return (
|
|
60
65
|
<div className="flex w-full flex-col gap-1.5">
|
|
61
66
|
{label && (
|
|
62
|
-
<label id={labelId} htmlFor={selectId} className=
|
|
67
|
+
<label id={labelId} htmlFor={selectId} className={labelHidden ? 'sr-only' : 'text-sm font-medium'}>
|
|
63
68
|
{label}
|
|
64
69
|
</label>
|
|
65
70
|
)}
|
|
@@ -2,7 +2,7 @@ import { render, screen, within } from '@testing-library/react';
|
|
|
2
2
|
import userEvent from '@testing-library/user-event';
|
|
3
3
|
import { axe } from 'jest-axe';
|
|
4
4
|
import { describe, expect, it } from 'vitest';
|
|
5
|
-
import { SiteHeader } from './SiteHeader';
|
|
5
|
+
import { SiteHeader, type SiteNavItem } from './SiteHeader';
|
|
6
6
|
|
|
7
7
|
const items = [
|
|
8
8
|
{ href: '/docs', label: 'Docs' },
|
|
@@ -84,3 +84,105 @@ describe('SiteHeader', () => {
|
|
|
84
84
|
expect(await axe(container)).toHaveNoViolations();
|
|
85
85
|
});
|
|
86
86
|
});
|
|
87
|
+
|
|
88
|
+
const megaItems: SiteNavItem[] = [
|
|
89
|
+
{
|
|
90
|
+
label: 'Dancers',
|
|
91
|
+
columns: [
|
|
92
|
+
{
|
|
93
|
+
heading: 'Plan',
|
|
94
|
+
items: [
|
|
95
|
+
{ href: '/events', label: 'All events', description: 'Every genre in Utah' },
|
|
96
|
+
{ href: '/deadlines', label: 'Deadlines' },
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
heading: 'Follow',
|
|
101
|
+
items: [{ href: '/brief', label: 'Deadline Brief' }],
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
{ href: '/directory', label: 'Directory' },
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
describe('SiteHeader mega menu', () => {
|
|
109
|
+
it('renders a disclosure trigger instead of a link for nested items', () => {
|
|
110
|
+
render(<SiteHeader brand={<span>Acme</span>} items={megaItems} />);
|
|
111
|
+
const trigger = screen.getByRole('button', { name: /Dancers/ });
|
|
112
|
+
expect(trigger).toHaveAttribute('aria-expanded', 'false');
|
|
113
|
+
expect(screen.getByRole('link', { name: 'Directory' })).toBeInTheDocument();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('opens on hover and exposes the panel links', async () => {
|
|
117
|
+
const user = userEvent.setup();
|
|
118
|
+
render(<SiteHeader brand={<span>Acme</span>} items={megaItems} />);
|
|
119
|
+
await user.hover(screen.getByRole('button', { name: /Dancers/ }));
|
|
120
|
+
expect(screen.getByRole('button', { name: /Dancers/ })).toHaveAttribute(
|
|
121
|
+
'aria-expanded',
|
|
122
|
+
'true'
|
|
123
|
+
);
|
|
124
|
+
expect(screen.getByRole('link', { name: /All events/ })).toBeInTheDocument();
|
|
125
|
+
expect(screen.getByText('Plan')).toBeInTheDocument();
|
|
126
|
+
expect(screen.getByText('Every genre in Utah')).toBeInTheDocument();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('closes on Escape and on an outside pointer', async () => {
|
|
130
|
+
const user = userEvent.setup();
|
|
131
|
+
render(
|
|
132
|
+
<div>
|
|
133
|
+
<SiteHeader brand={<span>Acme</span>} items={megaItems} />
|
|
134
|
+
<button type="button">Outside</button>
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
const trigger = screen.getByRole('button', { name: /Dancers/ });
|
|
138
|
+
await user.click(trigger);
|
|
139
|
+
expect(trigger).toHaveAttribute('aria-expanded', 'true');
|
|
140
|
+
await user.keyboard('{Escape}');
|
|
141
|
+
expect(trigger).toHaveAttribute('aria-expanded', 'false');
|
|
142
|
+
await user.click(trigger);
|
|
143
|
+
expect(trigger).toHaveAttribute('aria-expanded', 'true');
|
|
144
|
+
await user.click(screen.getByRole('button', { name: 'Outside' }));
|
|
145
|
+
expect(screen.getByRole('button', { name: /Dancers/ })).toHaveAttribute(
|
|
146
|
+
'aria-expanded',
|
|
147
|
+
'false'
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('moves focus into the panel with ArrowDown', async () => {
|
|
152
|
+
const user = userEvent.setup();
|
|
153
|
+
render(<SiteHeader brand={<span>Acme</span>} items={megaItems} />);
|
|
154
|
+
const trigger = screen.getByRole('button', { name: /Dancers/ });
|
|
155
|
+
trigger.focus();
|
|
156
|
+
await user.keyboard('{ArrowDown}');
|
|
157
|
+
expect(screen.getByRole('link', { name: /All events/ })).toHaveFocus();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('keeps the panel open while tabbing through its links', async () => {
|
|
161
|
+
const user = userEvent.setup();
|
|
162
|
+
render(<SiteHeader brand={<span>Acme</span>} items={megaItems} />);
|
|
163
|
+
const trigger = screen.getByRole('button', { name: /Dancers/ });
|
|
164
|
+
trigger.focus();
|
|
165
|
+
await user.keyboard('{ArrowDown}');
|
|
166
|
+
await user.tab();
|
|
167
|
+
expect(screen.getByRole('link', { name: /Deadlines/ })).toHaveFocus();
|
|
168
|
+
expect(trigger).toHaveAttribute('aria-expanded', 'true');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('renders nested groups in the mobile drawer', async () => {
|
|
172
|
+
const user = userEvent.setup();
|
|
173
|
+
render(<SiteHeader brand={<span>Acme</span>} items={megaItems} />);
|
|
174
|
+
await user.click(screen.getByRole('button', { name: 'Open menu' }));
|
|
175
|
+
const drawer = screen.getByRole('dialog', { name: 'Menu' });
|
|
176
|
+
expect(within(drawer).getByText('Dancers')).toBeInTheDocument();
|
|
177
|
+
expect(within(drawer).getByRole('link', { name: /All events/ })).toBeInTheDocument();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('has no accessibility violations with a panel open', async () => {
|
|
181
|
+
const user = userEvent.setup();
|
|
182
|
+
const { container } = render(
|
|
183
|
+
<SiteHeader brand={<span>Acme</span>} items={megaItems} activeHref="/events" />
|
|
184
|
+
);
|
|
185
|
+
await user.hover(screen.getByRole('button', { name: /Dancers/ }));
|
|
186
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
187
|
+
});
|
|
188
|
+
});
|