shadcn-rails 0.1.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.
- checksums.yaml +7 -0
- data/.dockerignore +40 -0
- data/CHANGELOG.md +54 -0
- data/CLAUDE.md +463 -0
- data/PROGRESS.md +485 -0
- data/README.md +1483 -0
- data/Rakefile +29 -0
- data/__tests__/controllers/__snapshots__/calendar_controller.test.js.snap +13 -0
- data/__tests__/controllers/__snapshots__/popover_controller.test.js.snap +46 -0
- data/__tests__/controllers/__snapshots__/sheet_controller.test.js.snap +111 -0
- data/__tests__/controllers/__snapshots__/tabs_controller.test.js.snap +27 -0
- data/__tests__/controllers/accordion_controller.test.js +904 -0
- data/__tests__/controllers/calendar_controller.test.js +1370 -0
- data/__tests__/controllers/carousel_controller.test.js +912 -0
- data/__tests__/controllers/checkbox_controller.test.js +454 -0
- data/__tests__/controllers/collapsible_controller.test.js +407 -0
- data/__tests__/controllers/combobox_controller.test.js +966 -0
- data/__tests__/controllers/context_menu_controller.test.js +627 -0
- data/__tests__/controllers/date_picker_controller.test.js +636 -0
- data/__tests__/controllers/dialog_controller.test.js +878 -0
- data/__tests__/controllers/drawer_controller.test.js +995 -0
- data/__tests__/controllers/menubar_controller.test.js +736 -0
- data/__tests__/controllers/navigation_menu_controller.test.js +598 -0
- data/__tests__/controllers/popover_controller.test.js +1007 -0
- data/__tests__/controllers/radio_group_controller.test.js +640 -0
- data/__tests__/controllers/resizable_controller.test.js +680 -0
- data/__tests__/controllers/select_controller.test.js +674 -0
- data/__tests__/controllers/sheet_controller.test.js +986 -0
- data/__tests__/controllers/slider_controller.test.js +1036 -0
- data/__tests__/controllers/switch_controller.test.js +424 -0
- data/__tests__/controllers/tabs_controller.test.js +907 -0
- data/__tests__/controllers/toggle_group_controller.test.js +839 -0
- data/__tests__/controllers/tooltip_controller.test.js +808 -0
- data/__tests__/helpers/stimulus-test-helper.js +203 -0
- data/app/assets/config/manifest.js +1 -0
- data/app/assets/javascripts/shadcn/controllers/accordion_controller.d.ts +53 -0
- data/app/assets/javascripts/shadcn/controllers/accordion_controller.js +140 -0
- data/app/assets/javascripts/shadcn/controllers/avatar_controller.d.ts +22 -0
- data/app/assets/javascripts/shadcn/controllers/avatar_controller.js +26 -0
- data/app/assets/javascripts/shadcn/controllers/calendar_controller.js +592 -0
- data/app/assets/javascripts/shadcn/controllers/carousel_controller.js +263 -0
- data/app/assets/javascripts/shadcn/controllers/checkbox_controller.d.ts +31 -0
- data/app/assets/javascripts/shadcn/controllers/checkbox_controller.js +48 -0
- data/app/assets/javascripts/shadcn/controllers/collapsible_controller.d.ts +43 -0
- data/app/assets/javascripts/shadcn/controllers/collapsible_controller.js +73 -0
- data/app/assets/javascripts/shadcn/controllers/combobox_controller.js +234 -0
- data/app/assets/javascripts/shadcn/controllers/command_controller.js +141 -0
- data/app/assets/javascripts/shadcn/controllers/command_dialog_controller.js +162 -0
- data/app/assets/javascripts/shadcn/controllers/context_menu_controller.js +202 -0
- data/app/assets/javascripts/shadcn/controllers/date_picker_controller.js +282 -0
- data/app/assets/javascripts/shadcn/controllers/dialog_controller.d.ts +67 -0
- data/app/assets/javascripts/shadcn/controllers/dialog_controller.js +187 -0
- data/app/assets/javascripts/shadcn/controllers/drawer_controller.d.ts +58 -0
- data/app/assets/javascripts/shadcn/controllers/drawer_controller.js +112 -0
- data/app/assets/javascripts/shadcn/controllers/dropdown_controller.d.ts +83 -0
- data/app/assets/javascripts/shadcn/controllers/dropdown_controller.js +225 -0
- data/app/assets/javascripts/shadcn/controllers/hover_card_controller.d.ts +59 -0
- data/app/assets/javascripts/shadcn/controllers/hover_card_controller.js +143 -0
- data/app/assets/javascripts/shadcn/controllers/input_otp_controller.d.ts +44 -0
- data/app/assets/javascripts/shadcn/controllers/input_otp_controller.js +206 -0
- data/app/assets/javascripts/shadcn/controllers/menubar_controller.js +323 -0
- data/app/assets/javascripts/shadcn/controllers/navigation_menu_controller.js +251 -0
- data/app/assets/javascripts/shadcn/controllers/popover_controller.d.ts +56 -0
- data/app/assets/javascripts/shadcn/controllers/popover_controller.js +141 -0
- data/app/assets/javascripts/shadcn/controllers/radio_group_controller.d.ts +47 -0
- data/app/assets/javascripts/shadcn/controllers/radio_group_controller.js +108 -0
- data/app/assets/javascripts/shadcn/controllers/resizable_controller.js +272 -0
- data/app/assets/javascripts/shadcn/controllers/scroll_area_controller.d.ts +44 -0
- data/app/assets/javascripts/shadcn/controllers/scroll_area_controller.js +74 -0
- data/app/assets/javascripts/shadcn/controllers/select_controller.d.ts +84 -0
- data/app/assets/javascripts/shadcn/controllers/select_controller.js +222 -0
- data/app/assets/javascripts/shadcn/controllers/sheet_controller.d.ts +60 -0
- data/app/assets/javascripts/shadcn/controllers/sheet_controller.js +151 -0
- data/app/assets/javascripts/shadcn/controllers/sidebar_controller.js +148 -0
- data/app/assets/javascripts/shadcn/controllers/slider_controller.d.ts +102 -0
- data/app/assets/javascripts/shadcn/controllers/slider_controller.js +364 -0
- data/app/assets/javascripts/shadcn/controllers/switch_controller.d.ts +46 -0
- data/app/assets/javascripts/shadcn/controllers/switch_controller.js +78 -0
- data/app/assets/javascripts/shadcn/controllers/tabs_controller.d.ts +51 -0
- data/app/assets/javascripts/shadcn/controllers/tabs_controller.js +126 -0
- data/app/assets/javascripts/shadcn/controllers/toast_controller.d.ts +37 -0
- data/app/assets/javascripts/shadcn/controllers/toast_controller.js +58 -0
- data/app/assets/javascripts/shadcn/controllers/toggle_controller.d.ts +27 -0
- data/app/assets/javascripts/shadcn/controllers/toggle_controller.js +42 -0
- data/app/assets/javascripts/shadcn/controllers/toggle_group_controller.d.ts +44 -0
- data/app/assets/javascripts/shadcn/controllers/toggle_group_controller.js +68 -0
- data/app/assets/javascripts/shadcn/controllers/tooltip_controller.d.ts +56 -0
- data/app/assets/javascripts/shadcn/controllers/tooltip_controller.js +117 -0
- data/app/assets/javascripts/shadcn/index.d.ts +74 -0
- data/app/assets/javascripts/shadcn/index.js +133 -0
- data/app/assets/stylesheets/.keep +0 -0
- data/app/assets/stylesheets/shadcn/base.css +445 -0
- data/app/assets/stylesheets/shadcn/components.css +513 -0
- data/app/assets/stylesheets/shadcn/index.css +18 -0
- data/app/assets/stylesheets/shadcn/themes/gray.css +68 -0
- data/app/assets/stylesheets/shadcn/themes/slate.css +68 -0
- data/app/assets/stylesheets/shadcn/themes/stone.css +68 -0
- data/app/assets/stylesheets/shadcn/themes/zinc.css +68 -0
- data/app/components/shadcn/accordion_component.rb +63 -0
- data/app/components/shadcn/accordion_content_component.rb +29 -0
- data/app/components/shadcn/accordion_item_component.rb +40 -0
- data/app/components/shadcn/accordion_trigger_component.rb +49 -0
- data/app/components/shadcn/alert_component.rb +75 -0
- data/app/components/shadcn/alert_description_component.rb +12 -0
- data/app/components/shadcn/alert_dialog_action_component.rb +24 -0
- data/app/components/shadcn/alert_dialog_cancel_component.rb +24 -0
- data/app/components/shadcn/alert_dialog_component.rb +71 -0
- data/app/components/shadcn/alert_dialog_content_component.rb +57 -0
- data/app/components/shadcn/alert_dialog_description_component.rb +12 -0
- data/app/components/shadcn/alert_dialog_footer_component.rb +19 -0
- data/app/components/shadcn/alert_dialog_header_component.rb +19 -0
- data/app/components/shadcn/alert_dialog_title_component.rb +12 -0
- data/app/components/shadcn/alert_title_component.rb +12 -0
- data/app/components/shadcn/aspect_ratio_component.rb +49 -0
- data/app/components/shadcn/avatar_component.rb +107 -0
- data/app/components/shadcn/avatar_fallback_component.rb +17 -0
- data/app/components/shadcn/badge_component.rb +49 -0
- data/app/components/shadcn/base_component.rb +100 -0
- data/app/components/shadcn/breadcrumb_component.rb +70 -0
- data/app/components/shadcn/breadcrumb_item_component.rb +50 -0
- data/app/components/shadcn/button_component.rb +141 -0
- data/app/components/shadcn/button_group_component.rb +69 -0
- data/app/components/shadcn/calendar_component.rb +337 -0
- data/app/components/shadcn/card_action_component.rb +10 -0
- data/app/components/shadcn/card_component.rb +63 -0
- data/app/components/shadcn/card_content_component.rb +19 -0
- data/app/components/shadcn/card_description_component.rb +12 -0
- data/app/components/shadcn/card_footer_component.rb +12 -0
- data/app/components/shadcn/card_header_component.rb +24 -0
- data/app/components/shadcn/card_title_component.rb +18 -0
- data/app/components/shadcn/carousel_component.rb +275 -0
- data/app/components/shadcn/checkbox_component.rb +103 -0
- data/app/components/shadcn/collapsible_component.rb +66 -0
- data/app/components/shadcn/collapsible_content_component.rb +28 -0
- data/app/components/shadcn/combobox_component.rb +322 -0
- data/app/components/shadcn/command_component.rb +52 -0
- data/app/components/shadcn/command_dialog_component.rb +76 -0
- data/app/components/shadcn/command_empty_component.rb +12 -0
- data/app/components/shadcn/command_group_component.rb +34 -0
- data/app/components/shadcn/command_input_component.rb +59 -0
- data/app/components/shadcn/command_item_component.rb +48 -0
- data/app/components/shadcn/command_list_component.rb +38 -0
- data/app/components/shadcn/command_separator_component.rb +12 -0
- data/app/components/shadcn/command_shortcut_component.rb +12 -0
- data/app/components/shadcn/context_menu_component.rb +64 -0
- data/app/components/shadcn/context_menu_content_component.rb +44 -0
- data/app/components/shadcn/context_menu_item_component.rb +63 -0
- data/app/components/shadcn/context_menu_label_component.rb +18 -0
- data/app/components/shadcn/context_menu_separator_component.rb +12 -0
- data/app/components/shadcn/context_menu_shortcut_component.rb +12 -0
- data/app/components/shadcn/date_picker_component.rb +368 -0
- data/app/components/shadcn/dialog_component.rb +77 -0
- data/app/components/shadcn/dialog_content_component.rb +91 -0
- data/app/components/shadcn/dialog_description_component.rb +12 -0
- data/app/components/shadcn/dialog_footer_component.rb +12 -0
- data/app/components/shadcn/dialog_header_component.rb +19 -0
- data/app/components/shadcn/dialog_title_component.rb +12 -0
- data/app/components/shadcn/drawer_component.rb +72 -0
- data/app/components/shadcn/drawer_content_component.rb +76 -0
- data/app/components/shadcn/drawer_description_component.rb +12 -0
- data/app/components/shadcn/drawer_footer_component.rb +12 -0
- data/app/components/shadcn/drawer_header_component.rb +19 -0
- data/app/components/shadcn/drawer_title_component.rb +12 -0
- data/app/components/shadcn/dropdown_menu_component.rb +75 -0
- data/app/components/shadcn/dropdown_menu_content_component.rb +49 -0
- data/app/components/shadcn/dropdown_menu_group_component.rb +10 -0
- data/app/components/shadcn/dropdown_menu_item_component.rb +63 -0
- data/app/components/shadcn/dropdown_menu_label_component.rb +18 -0
- data/app/components/shadcn/dropdown_menu_separator_component.rb +12 -0
- data/app/components/shadcn/dropdown_menu_shortcut_component.rb +12 -0
- data/app/components/shadcn/empty_component.rb +48 -0
- data/app/components/shadcn/empty_content_component.rb +12 -0
- data/app/components/shadcn/empty_description_component.rb +12 -0
- data/app/components/shadcn/empty_header_component.rb +29 -0
- data/app/components/shadcn/empty_media_component.rb +21 -0
- data/app/components/shadcn/empty_title_component.rb +12 -0
- data/app/components/shadcn/field_component.rb +113 -0
- data/app/components/shadcn/hover_card_component.rb +64 -0
- data/app/components/shadcn/hover_card_content_component.rb +36 -0
- data/app/components/shadcn/input_component.rb +108 -0
- data/app/components/shadcn/input_group_component.rb +70 -0
- data/app/components/shadcn/input_otp_component.rb +183 -0
- data/app/components/shadcn/item_actions_component.rb +12 -0
- data/app/components/shadcn/item_component.rb +98 -0
- data/app/components/shadcn/item_content_component.rb +24 -0
- data/app/components/shadcn/item_description_component.rb +12 -0
- data/app/components/shadcn/item_footer_component.rb +12 -0
- data/app/components/shadcn/item_group_component.rb +24 -0
- data/app/components/shadcn/item_header_component.rb +12 -0
- data/app/components/shadcn/item_media_component.rb +22 -0
- data/app/components/shadcn/item_separator_component.rb +12 -0
- data/app/components/shadcn/item_title_component.rb +12 -0
- data/app/components/shadcn/kbd_component.rb +36 -0
- data/app/components/shadcn/label_component.rb +49 -0
- data/app/components/shadcn/menubar_checkbox_item_component.rb +76 -0
- data/app/components/shadcn/menubar_component.rb +56 -0
- data/app/components/shadcn/menubar_content_component.rb +64 -0
- data/app/components/shadcn/menubar_item_component.rb +65 -0
- data/app/components/shadcn/menubar_label_component.rb +27 -0
- data/app/components/shadcn/menubar_menu_component.rb +34 -0
- data/app/components/shadcn/menubar_radio_group_component.rb +42 -0
- data/app/components/shadcn/menubar_radio_item_component.rb +76 -0
- data/app/components/shadcn/menubar_separator_component.rb +22 -0
- data/app/components/shadcn/menubar_shortcut_component.rb +21 -0
- data/app/components/shadcn/menubar_sub_component.rb +38 -0
- data/app/components/shadcn/menubar_sub_content_component.rb +45 -0
- data/app/components/shadcn/menubar_sub_trigger_component.rb +59 -0
- data/app/components/shadcn/menubar_trigger_component.rb +31 -0
- data/app/components/shadcn/native_select_component.rb +150 -0
- data/app/components/shadcn/navigation_menu_component.rb +76 -0
- data/app/components/shadcn/navigation_menu_content_component.rb +30 -0
- data/app/components/shadcn/navigation_menu_item_component.rb +39 -0
- data/app/components/shadcn/navigation_menu_link_component.rb +38 -0
- data/app/components/shadcn/navigation_menu_list_component.rb +29 -0
- data/app/components/shadcn/navigation_menu_trigger_component.rb +59 -0
- data/app/components/shadcn/pagination_component.rb +195 -0
- data/app/components/shadcn/pagination_content_component.rb +47 -0
- data/app/components/shadcn/pagination_ellipsis_component.rb +30 -0
- data/app/components/shadcn/pagination_item_component.rb +53 -0
- data/app/components/shadcn/pagination_next_component.rb +48 -0
- data/app/components/shadcn/pagination_previous_component.rb +48 -0
- data/app/components/shadcn/popover_component.rb +76 -0
- data/app/components/shadcn/popover_content_component.rb +25 -0
- data/app/components/shadcn/progress_component.rb +77 -0
- data/app/components/shadcn/radio_group_component.rb +129 -0
- data/app/components/shadcn/radio_group_item_component.rb +109 -0
- data/app/components/shadcn/resizable_handle_component.rb +98 -0
- data/app/components/shadcn/resizable_panel_component.rb +56 -0
- data/app/components/shadcn/resizable_panel_group_component.rb +94 -0
- data/app/components/shadcn/scroll_area_component.rb +110 -0
- data/app/components/shadcn/select_component.rb +151 -0
- data/app/components/shadcn/select_group_component.rb +32 -0
- data/app/components/shadcn/select_item_component.rb +59 -0
- data/app/components/shadcn/select_separator_component.rb +12 -0
- data/app/components/shadcn/separator_component.rb +54 -0
- data/app/components/shadcn/sheet_component.rb +82 -0
- data/app/components/shadcn/sheet_content_component.rb +95 -0
- data/app/components/shadcn/sheet_description_component.rb +12 -0
- data/app/components/shadcn/sheet_footer_component.rb +12 -0
- data/app/components/shadcn/sheet_header_component.rb +19 -0
- data/app/components/shadcn/sheet_title_component.rb +12 -0
- data/app/components/shadcn/sidebar_component.rb +180 -0
- data/app/components/shadcn/sidebar_content_component.rb +32 -0
- data/app/components/shadcn/sidebar_footer_component.rb +24 -0
- data/app/components/shadcn/sidebar_group_action_component.rb +26 -0
- data/app/components/shadcn/sidebar_group_component.rb +38 -0
- data/app/components/shadcn/sidebar_group_content_component.rb +32 -0
- data/app/components/shadcn/sidebar_group_label_component.rb +25 -0
- data/app/components/shadcn/sidebar_header_component.rb +24 -0
- data/app/components/shadcn/sidebar_inset_component.rb +25 -0
- data/app/components/shadcn/sidebar_menu_action_component.rb +37 -0
- data/app/components/shadcn/sidebar_menu_badge_component.rb +25 -0
- data/app/components/shadcn/sidebar_menu_button_component.rb +52 -0
- data/app/components/shadcn/sidebar_menu_component.rb +32 -0
- data/app/components/shadcn/sidebar_menu_item_component.rb +41 -0
- data/app/components/shadcn/sidebar_menu_skeleton_component.rb +46 -0
- data/app/components/shadcn/sidebar_menu_sub_button_component.rb +43 -0
- data/app/components/shadcn/sidebar_menu_sub_component.rb +33 -0
- data/app/components/shadcn/sidebar_menu_sub_item_component.rb +30 -0
- data/app/components/shadcn/sidebar_provider_component.rb +57 -0
- data/app/components/shadcn/sidebar_rail_component.rb +30 -0
- data/app/components/shadcn/sidebar_separator_component.rb +24 -0
- data/app/components/shadcn/sidebar_trigger_component.rb +51 -0
- data/app/components/shadcn/skeleton_component.rb +29 -0
- data/app/components/shadcn/slider_component.rb +76 -0
- data/app/components/shadcn/spinner_component.rb +67 -0
- data/app/components/shadcn/switch_component.rb +147 -0
- data/app/components/shadcn/table_body_component.rb +16 -0
- data/app/components/shadcn/table_caption_component.rb +12 -0
- data/app/components/shadcn/table_cell_component.rb +12 -0
- data/app/components/shadcn/table_component.rb +57 -0
- data/app/components/shadcn/table_footer_component.rb +16 -0
- data/app/components/shadcn/table_head_component.rb +12 -0
- data/app/components/shadcn/table_header_component.rb +16 -0
- data/app/components/shadcn/table_row_component.rb +40 -0
- data/app/components/shadcn/tabs_component.rb +78 -0
- data/app/components/shadcn/tabs_content_component.rb +32 -0
- data/app/components/shadcn/tabs_list_component.rb +30 -0
- data/app/components/shadcn/tabs_trigger_component.rb +37 -0
- data/app/components/shadcn/textarea_component.rb +84 -0
- data/app/components/shadcn/toast_action_component.rb +18 -0
- data/app/components/shadcn/toast_component.rb +114 -0
- data/app/components/shadcn/toast_description_component.rb +12 -0
- data/app/components/shadcn/toast_title_component.rb +12 -0
- data/app/components/shadcn/toast_viewport_component.rb +12 -0
- data/app/components/shadcn/toggle_component.rb +77 -0
- data/app/components/shadcn/toggle_group_component.rb +96 -0
- data/app/components/shadcn/toggle_group_item_component.rb +62 -0
- data/app/components/shadcn/tooltip_component.rb +89 -0
- data/app/components/shadcn/typography_component.rb +112 -0
- data/babel.config.cjs +5 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/config/importmap.rb +5 -0
- data/fly.toml +26 -0
- data/jest.config.js +19 -0
- data/jest.setup.js +8 -0
- data/lib/generators/shadcn/component/component_generator.rb +188 -0
- data/lib/generators/shadcn/install/install_generator.rb +140 -0
- data/lib/generators/shadcn/install/templates/initializer.rb.tt +35 -0
- data/lib/generators/shadcn/install/templates/shadcn.yml.tt +35 -0
- data/lib/generators/shadcn/theme/theme_generator.rb +128 -0
- data/lib/shadcn/rails/class_merger.rb +228 -0
- data/lib/shadcn/rails/configuration.rb +341 -0
- data/lib/shadcn/rails/engine.rb +59 -0
- data/lib/shadcn/rails/helpers/class_name_helper.rb +35 -0
- data/lib/shadcn/rails/helpers/component_helper.rb +60 -0
- data/lib/shadcn/rails/helpers/pagination_helper.rb +187 -0
- data/lib/shadcn/rails/version.rb +7 -0
- data/lib/shadcn/rails.rb +179 -0
- data/package-lock.json +7415 -0
- data/package.json +68 -0
- data/rollup.config.js +29 -0
- data/sig/shadcn/rails.rbs +6 -0
- metadata +526 -0
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
import { Application } from "@hotwired/stimulus"
|
|
2
|
+
import NavigationMenuController from "../../app/assets/javascripts/shadcn/controllers/navigation_menu_controller.js"
|
|
3
|
+
import { setupController, cleanupController, click, nextFrame, wait } from '../helpers/stimulus-test-helper.js'
|
|
4
|
+
|
|
5
|
+
describe("NavigationMenuController", () => {
|
|
6
|
+
let application
|
|
7
|
+
let element
|
|
8
|
+
let controller
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
cleanupController(application)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
describe("basic rendering and initialization", () => {
|
|
15
|
+
const basicHTML = `
|
|
16
|
+
<nav data-controller="shadcn--navigation-menu"
|
|
17
|
+
data-shadcn--navigation-menu-open-index-value="-1"
|
|
18
|
+
data-shadcn--navigation-menu-delay-duration-value="200"
|
|
19
|
+
data-shadcn--navigation-menu-skip-delay-duration-value="300">
|
|
20
|
+
<ul data-shadcn--navigation-menu-target="list">
|
|
21
|
+
<li data-shadcn--navigation-menu-target="item">
|
|
22
|
+
<button data-shadcn--navigation-menu-target="trigger"
|
|
23
|
+
data-action="click->shadcn--navigation-menu#toggle mouseenter->shadcn--navigation-menu#hoverOpen mouseleave->shadcn--navigation-menu#hoverClose"
|
|
24
|
+
aria-expanded="false">Products</button>
|
|
25
|
+
<div data-shadcn--navigation-menu-target="content" hidden>
|
|
26
|
+
<a href="/product1">Product 1</a>
|
|
27
|
+
</div>
|
|
28
|
+
</li>
|
|
29
|
+
<li data-shadcn--navigation-menu-target="item">
|
|
30
|
+
<button data-shadcn--navigation-menu-target="trigger"
|
|
31
|
+
data-action="click->shadcn--navigation-menu#toggle mouseenter->shadcn--navigation-menu#hoverOpen mouseleave->shadcn--navigation-menu#hoverClose"
|
|
32
|
+
aria-expanded="false">Services</button>
|
|
33
|
+
<div data-shadcn--navigation-menu-target="content" hidden>
|
|
34
|
+
<a href="/service1">Service 1</a>
|
|
35
|
+
</div>
|
|
36
|
+
</li>
|
|
37
|
+
</ul>
|
|
38
|
+
</nav>
|
|
39
|
+
`
|
|
40
|
+
|
|
41
|
+
beforeEach(async () => {
|
|
42
|
+
const setup = await setupController(NavigationMenuController, basicHTML, 'shadcn--navigation-menu')
|
|
43
|
+
application = setup.application
|
|
44
|
+
element = setup.element
|
|
45
|
+
controller = setup.controller
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test("initializes with closed state", () => {
|
|
49
|
+
expect(controller.openIndexValue).toBe(-1)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test("initializes isOpen to false", () => {
|
|
53
|
+
expect(controller.isOpen).toBe(false)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test("initializes with default delay values", () => {
|
|
57
|
+
expect(controller.delayDurationValue).toBe(200)
|
|
58
|
+
expect(controller.skipDelayDurationValue).toBe(300)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test("has list target", () => {
|
|
62
|
+
expect(controller.hasListTarget).toBe(true)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test("has item targets", () => {
|
|
66
|
+
expect(controller.itemTargets.length).toBe(2)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test("has trigger targets", () => {
|
|
70
|
+
expect(controller.triggerTargets.length).toBe(2)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test("has content targets", () => {
|
|
74
|
+
expect(controller.contentTargets.length).toBe(2)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test("all content is initially hidden", () => {
|
|
78
|
+
controller.contentTargets.forEach(content => {
|
|
79
|
+
expect(content.hidden).toBe(true)
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
describe("toggle functionality", () => {
|
|
85
|
+
const toggleHTML = `
|
|
86
|
+
<nav data-controller="shadcn--navigation-menu"
|
|
87
|
+
data-shadcn--navigation-menu-open-index-value="-1">
|
|
88
|
+
<ul data-shadcn--navigation-menu-target="list">
|
|
89
|
+
<li data-shadcn--navigation-menu-target="item">
|
|
90
|
+
<button data-shadcn--navigation-menu-target="trigger"
|
|
91
|
+
data-action="click->shadcn--navigation-menu#toggle"
|
|
92
|
+
aria-expanded="false">Products</button>
|
|
93
|
+
<div data-shadcn--navigation-menu-target="content" hidden>Content 1</div>
|
|
94
|
+
</li>
|
|
95
|
+
<li data-shadcn--navigation-menu-target="item">
|
|
96
|
+
<button data-shadcn--navigation-menu-target="trigger"
|
|
97
|
+
data-action="click->shadcn--navigation-menu#toggle"
|
|
98
|
+
aria-expanded="false">Services</button>
|
|
99
|
+
<div data-shadcn--navigation-menu-target="content" hidden>Content 2</div>
|
|
100
|
+
</li>
|
|
101
|
+
</ul>
|
|
102
|
+
</nav>
|
|
103
|
+
`
|
|
104
|
+
|
|
105
|
+
beforeEach(async () => {
|
|
106
|
+
const setup = await setupController(NavigationMenuController, toggleHTML, 'shadcn--navigation-menu')
|
|
107
|
+
application = setup.application
|
|
108
|
+
element = setup.element
|
|
109
|
+
controller = setup.controller
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
test("opens item on toggle", async () => {
|
|
113
|
+
const trigger = controller.triggerTargets[0]
|
|
114
|
+
controller.toggle({ currentTarget: trigger, preventDefault: jest.fn() })
|
|
115
|
+
await nextFrame()
|
|
116
|
+
|
|
117
|
+
expect(controller.openIndexValue).toBe(0)
|
|
118
|
+
expect(controller.isOpen).toBe(true)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test("sets aria-expanded to true", async () => {
|
|
122
|
+
const trigger = controller.triggerTargets[0]
|
|
123
|
+
controller.toggle({ currentTarget: trigger, preventDefault: jest.fn() })
|
|
124
|
+
await nextFrame()
|
|
125
|
+
|
|
126
|
+
expect(trigger.getAttribute("aria-expanded")).toBe("true")
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test("shows content when opened", async () => {
|
|
130
|
+
const trigger = controller.triggerTargets[0]
|
|
131
|
+
controller.toggle({ currentTarget: trigger, preventDefault: jest.fn() })
|
|
132
|
+
await nextFrame()
|
|
133
|
+
|
|
134
|
+
const content = controller.contentTargets[0]
|
|
135
|
+
expect(content.hidden).toBe(false)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test("sets content data-state to open", async () => {
|
|
139
|
+
const trigger = controller.triggerTargets[0]
|
|
140
|
+
controller.toggle({ currentTarget: trigger, preventDefault: jest.fn() })
|
|
141
|
+
await nextFrame()
|
|
142
|
+
|
|
143
|
+
const content = controller.contentTargets[0]
|
|
144
|
+
expect(content.dataset.state).toBe("open")
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test("closes item on second toggle", async () => {
|
|
148
|
+
const trigger = controller.triggerTargets[0]
|
|
149
|
+
controller.toggle({ currentTarget: trigger, preventDefault: jest.fn() })
|
|
150
|
+
await nextFrame()
|
|
151
|
+
controller.toggle({ currentTarget: trigger, preventDefault: jest.fn() })
|
|
152
|
+
await nextFrame()
|
|
153
|
+
|
|
154
|
+
expect(controller.openIndexValue).toBe(-1)
|
|
155
|
+
expect(controller.isOpen).toBe(false)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test("switches to different item on toggle", async () => {
|
|
159
|
+
const trigger1 = controller.triggerTargets[0]
|
|
160
|
+
const trigger2 = controller.triggerTargets[1]
|
|
161
|
+
|
|
162
|
+
controller.toggle({ currentTarget: trigger1, preventDefault: jest.fn() })
|
|
163
|
+
await nextFrame()
|
|
164
|
+
|
|
165
|
+
expect(controller.openIndexValue).toBe(0)
|
|
166
|
+
|
|
167
|
+
controller.toggle({ currentTarget: trigger2, preventDefault: jest.fn() })
|
|
168
|
+
await nextFrame()
|
|
169
|
+
|
|
170
|
+
expect(controller.openIndexValue).toBe(1)
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
test("sets wasClickOpened flag on toggle", async () => {
|
|
174
|
+
const trigger = controller.triggerTargets[0]
|
|
175
|
+
controller.toggle({ currentTarget: trigger, preventDefault: jest.fn() })
|
|
176
|
+
await nextFrame()
|
|
177
|
+
|
|
178
|
+
expect(controller.wasClickOpened).toBe(true)
|
|
179
|
+
})
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
describe("openItem and closeItem", () => {
|
|
183
|
+
const itemHTML = `
|
|
184
|
+
<nav data-controller="shadcn--navigation-menu"
|
|
185
|
+
data-shadcn--navigation-menu-open-index-value="-1">
|
|
186
|
+
<ul data-shadcn--navigation-menu-target="list">
|
|
187
|
+
<li data-shadcn--navigation-menu-target="item">
|
|
188
|
+
<button data-shadcn--navigation-menu-target="trigger" aria-expanded="false">Menu 1</button>
|
|
189
|
+
<div data-shadcn--navigation-menu-target="content" hidden>Content 1</div>
|
|
190
|
+
</li>
|
|
191
|
+
<li data-shadcn--navigation-menu-target="item">
|
|
192
|
+
<button data-shadcn--navigation-menu-target="trigger" aria-expanded="false">Menu 2</button>
|
|
193
|
+
<div data-shadcn--navigation-menu-target="content" hidden>Content 2</div>
|
|
194
|
+
</li>
|
|
195
|
+
</ul>
|
|
196
|
+
</nav>
|
|
197
|
+
`
|
|
198
|
+
|
|
199
|
+
beforeEach(async () => {
|
|
200
|
+
const setup = await setupController(NavigationMenuController, itemHTML, 'shadcn--navigation-menu')
|
|
201
|
+
application = setup.application
|
|
202
|
+
element = setup.element
|
|
203
|
+
controller = setup.controller
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
test("openItem opens specified index", async () => {
|
|
207
|
+
controller.openItem(0)
|
|
208
|
+
await nextFrame()
|
|
209
|
+
|
|
210
|
+
expect(controller.openIndexValue).toBe(0)
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
test("openItem ignores invalid index (negative)", async () => {
|
|
214
|
+
controller.openItem(-1)
|
|
215
|
+
await nextFrame()
|
|
216
|
+
|
|
217
|
+
expect(controller.openIndexValue).toBe(-1)
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
test("openItem ignores invalid index (too high)", async () => {
|
|
221
|
+
controller.openItem(99)
|
|
222
|
+
await nextFrame()
|
|
223
|
+
|
|
224
|
+
expect(controller.openIndexValue).toBe(-1)
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
test("openItem closes previous item when opening new one", async () => {
|
|
228
|
+
controller.openItem(0)
|
|
229
|
+
await nextFrame()
|
|
230
|
+
|
|
231
|
+
controller.openItem(1)
|
|
232
|
+
await nextFrame()
|
|
233
|
+
|
|
234
|
+
const trigger0 = controller.triggerTargets[0]
|
|
235
|
+
const content0 = controller.contentTargets[0]
|
|
236
|
+
|
|
237
|
+
expect(trigger0.getAttribute("aria-expanded")).toBe("false")
|
|
238
|
+
expect(content0.dataset.state).toBe("closed")
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
test("closeItem closes specified index", async () => {
|
|
242
|
+
controller.openItem(0)
|
|
243
|
+
await nextFrame()
|
|
244
|
+
|
|
245
|
+
controller.closeItem(0)
|
|
246
|
+
await nextFrame()
|
|
247
|
+
|
|
248
|
+
const trigger = controller.triggerTargets[0]
|
|
249
|
+
expect(trigger.getAttribute("aria-expanded")).toBe("false")
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
test("sets motion direction when switching items", async () => {
|
|
253
|
+
controller.openItem(0)
|
|
254
|
+
await nextFrame()
|
|
255
|
+
|
|
256
|
+
controller.openItem(1)
|
|
257
|
+
await nextFrame()
|
|
258
|
+
|
|
259
|
+
const content1 = controller.contentTargets[1]
|
|
260
|
+
expect(content1.dataset.motion).toBe("from-end")
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
test("sets opposite motion direction", async () => {
|
|
264
|
+
controller.openItem(1)
|
|
265
|
+
await nextFrame()
|
|
266
|
+
|
|
267
|
+
controller.openItem(0)
|
|
268
|
+
await nextFrame()
|
|
269
|
+
|
|
270
|
+
const content0 = controller.contentTargets[0]
|
|
271
|
+
expect(content0.dataset.motion).toBe("from-start")
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
describe("closeAll", () => {
|
|
276
|
+
const closeAllHTML = `
|
|
277
|
+
<nav data-controller="shadcn--navigation-menu"
|
|
278
|
+
data-shadcn--navigation-menu-open-index-value="-1">
|
|
279
|
+
<ul data-shadcn--navigation-menu-target="list">
|
|
280
|
+
<li data-shadcn--navigation-menu-target="item">
|
|
281
|
+
<button data-shadcn--navigation-menu-target="trigger" aria-expanded="false">Menu</button>
|
|
282
|
+
<div data-shadcn--navigation-menu-target="content" hidden>Content</div>
|
|
283
|
+
</li>
|
|
284
|
+
</ul>
|
|
285
|
+
</nav>
|
|
286
|
+
`
|
|
287
|
+
|
|
288
|
+
beforeEach(async () => {
|
|
289
|
+
const setup = await setupController(NavigationMenuController, closeAllHTML, 'shadcn--navigation-menu')
|
|
290
|
+
application = setup.application
|
|
291
|
+
element = setup.element
|
|
292
|
+
controller = setup.controller
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
test("resets openIndexValue to -1", async () => {
|
|
296
|
+
controller.openItem(0)
|
|
297
|
+
await nextFrame()
|
|
298
|
+
|
|
299
|
+
controller.closeAll()
|
|
300
|
+
await nextFrame()
|
|
301
|
+
|
|
302
|
+
expect(controller.openIndexValue).toBe(-1)
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
test("resets isOpen to false", async () => {
|
|
306
|
+
controller.openItem(0)
|
|
307
|
+
await nextFrame()
|
|
308
|
+
|
|
309
|
+
controller.closeAll()
|
|
310
|
+
await nextFrame()
|
|
311
|
+
|
|
312
|
+
expect(controller.isOpen).toBe(false)
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
test("resets wasClickOpened to false", async () => {
|
|
316
|
+
const trigger = controller.triggerTargets[0]
|
|
317
|
+
controller.toggle({ currentTarget: trigger, preventDefault: jest.fn() })
|
|
318
|
+
await nextFrame()
|
|
319
|
+
|
|
320
|
+
controller.closeAll()
|
|
321
|
+
await nextFrame()
|
|
322
|
+
|
|
323
|
+
expect(controller.wasClickOpened).toBe(false)
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
test("sets all triggers to aria-expanded false", async () => {
|
|
327
|
+
controller.openItem(0)
|
|
328
|
+
await nextFrame()
|
|
329
|
+
|
|
330
|
+
controller.closeAll()
|
|
331
|
+
await nextFrame()
|
|
332
|
+
|
|
333
|
+
controller.triggerTargets.forEach(trigger => {
|
|
334
|
+
expect(trigger.getAttribute("aria-expanded")).toBe("false")
|
|
335
|
+
})
|
|
336
|
+
})
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
describe("keyboard navigation", () => {
|
|
340
|
+
const keyboardHTML = `
|
|
341
|
+
<nav data-controller="shadcn--navigation-menu"
|
|
342
|
+
data-shadcn--navigation-menu-open-index-value="-1">
|
|
343
|
+
<ul data-shadcn--navigation-menu-target="list">
|
|
344
|
+
<li data-shadcn--navigation-menu-target="item">
|
|
345
|
+
<button data-shadcn--navigation-menu-target="trigger" aria-expanded="false">Menu 1</button>
|
|
346
|
+
<div data-shadcn--navigation-menu-target="content" hidden>Content 1</div>
|
|
347
|
+
</li>
|
|
348
|
+
<li data-shadcn--navigation-menu-target="item">
|
|
349
|
+
<button data-shadcn--navigation-menu-target="trigger" aria-expanded="false">Menu 2</button>
|
|
350
|
+
<div data-shadcn--navigation-menu-target="content" hidden>Content 2</div>
|
|
351
|
+
</li>
|
|
352
|
+
<li data-shadcn--navigation-menu-target="item">
|
|
353
|
+
<button data-shadcn--navigation-menu-target="trigger" aria-expanded="false">Menu 3</button>
|
|
354
|
+
<div data-shadcn--navigation-menu-target="content" hidden>Content 3</div>
|
|
355
|
+
</li>
|
|
356
|
+
</ul>
|
|
357
|
+
</nav>
|
|
358
|
+
`
|
|
359
|
+
|
|
360
|
+
beforeEach(async () => {
|
|
361
|
+
const setup = await setupController(NavigationMenuController, keyboardHTML, 'shadcn--navigation-menu')
|
|
362
|
+
application = setup.application
|
|
363
|
+
element = setup.element
|
|
364
|
+
controller = setup.controller
|
|
365
|
+
|
|
366
|
+
// Open the first menu to enable keyboard navigation
|
|
367
|
+
controller.openItem(0)
|
|
368
|
+
await nextFrame()
|
|
369
|
+
})
|
|
370
|
+
|
|
371
|
+
test("ArrowRight navigates to next item", async () => {
|
|
372
|
+
controller.handleKeydown({ key: "ArrowRight", preventDefault: jest.fn() })
|
|
373
|
+
await nextFrame()
|
|
374
|
+
|
|
375
|
+
expect(controller.openIndexValue).toBe(1)
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
test("ArrowRight wraps to first item", async () => {
|
|
379
|
+
controller.openItem(2)
|
|
380
|
+
await nextFrame()
|
|
381
|
+
|
|
382
|
+
controller.handleKeydown({ key: "ArrowRight", preventDefault: jest.fn() })
|
|
383
|
+
await nextFrame()
|
|
384
|
+
|
|
385
|
+
expect(controller.openIndexValue).toBe(0)
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
test("ArrowLeft navigates to previous item", async () => {
|
|
389
|
+
controller.openItem(1)
|
|
390
|
+
await nextFrame()
|
|
391
|
+
|
|
392
|
+
controller.handleKeydown({ key: "ArrowLeft", preventDefault: jest.fn() })
|
|
393
|
+
await nextFrame()
|
|
394
|
+
|
|
395
|
+
expect(controller.openIndexValue).toBe(0)
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
test("ArrowLeft wraps to last item", async () => {
|
|
399
|
+
controller.handleKeydown({ key: "ArrowLeft", preventDefault: jest.fn() })
|
|
400
|
+
await nextFrame()
|
|
401
|
+
|
|
402
|
+
expect(controller.openIndexValue).toBe(2)
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
test("Escape closes all menus", async () => {
|
|
406
|
+
controller.handleKeydown({ key: "Escape", preventDefault: jest.fn() })
|
|
407
|
+
await nextFrame()
|
|
408
|
+
|
|
409
|
+
expect(controller.isOpen).toBe(false)
|
|
410
|
+
expect(controller.openIndexValue).toBe(-1)
|
|
411
|
+
})
|
|
412
|
+
|
|
413
|
+
test("prevents default on navigation keys", () => {
|
|
414
|
+
const preventDefault = jest.fn()
|
|
415
|
+
controller.handleKeydown({ key: "ArrowRight", preventDefault })
|
|
416
|
+
expect(preventDefault).toHaveBeenCalled()
|
|
417
|
+
|
|
418
|
+
preventDefault.mockClear()
|
|
419
|
+
controller.handleKeydown({ key: "ArrowLeft", preventDefault })
|
|
420
|
+
expect(preventDefault).toHaveBeenCalled()
|
|
421
|
+
})
|
|
422
|
+
})
|
|
423
|
+
|
|
424
|
+
describe("click outside handling", () => {
|
|
425
|
+
const clickOutsideHTML = `
|
|
426
|
+
<nav data-controller="shadcn--navigation-menu"
|
|
427
|
+
data-shadcn--navigation-menu-open-index-value="-1">
|
|
428
|
+
<ul data-shadcn--navigation-menu-target="list">
|
|
429
|
+
<li data-shadcn--navigation-menu-target="item">
|
|
430
|
+
<button data-shadcn--navigation-menu-target="trigger" aria-expanded="false">Menu</button>
|
|
431
|
+
<div data-shadcn--navigation-menu-target="content" hidden>Content</div>
|
|
432
|
+
</li>
|
|
433
|
+
</ul>
|
|
434
|
+
</nav>
|
|
435
|
+
`
|
|
436
|
+
|
|
437
|
+
beforeEach(async () => {
|
|
438
|
+
const setup = await setupController(NavigationMenuController, clickOutsideHTML, 'shadcn--navigation-menu')
|
|
439
|
+
application = setup.application
|
|
440
|
+
element = setup.element
|
|
441
|
+
controller = setup.controller
|
|
442
|
+
})
|
|
443
|
+
|
|
444
|
+
test("closes on click outside", async () => {
|
|
445
|
+
controller.openItem(0)
|
|
446
|
+
await nextFrame()
|
|
447
|
+
|
|
448
|
+
const outsideElement = document.createElement("div")
|
|
449
|
+
document.body.appendChild(outsideElement)
|
|
450
|
+
|
|
451
|
+
controller.handleClickOutside({ target: outsideElement })
|
|
452
|
+
await nextFrame()
|
|
453
|
+
|
|
454
|
+
expect(controller.isOpen).toBe(false)
|
|
455
|
+
|
|
456
|
+
document.body.removeChild(outsideElement)
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
test("does not close on click inside", async () => {
|
|
460
|
+
controller.openItem(0)
|
|
461
|
+
await nextFrame()
|
|
462
|
+
|
|
463
|
+
controller.handleClickOutside({ target: element })
|
|
464
|
+
await nextFrame()
|
|
465
|
+
|
|
466
|
+
expect(controller.isOpen).toBe(true)
|
|
467
|
+
})
|
|
468
|
+
})
|
|
469
|
+
|
|
470
|
+
describe("timer management", () => {
|
|
471
|
+
const timerHTML = `
|
|
472
|
+
<nav data-controller="shadcn--navigation-menu"
|
|
473
|
+
data-shadcn--navigation-menu-open-index-value="-1"
|
|
474
|
+
data-shadcn--navigation-menu-delay-duration-value="50"
|
|
475
|
+
data-shadcn--navigation-menu-skip-delay-duration-value="50">
|
|
476
|
+
<ul data-shadcn--navigation-menu-target="list">
|
|
477
|
+
<li data-shadcn--navigation-menu-target="item">
|
|
478
|
+
<button data-shadcn--navigation-menu-target="trigger"
|
|
479
|
+
data-action="mouseenter->shadcn--navigation-menu#hoverOpen mouseleave->shadcn--navigation-menu#hoverClose"
|
|
480
|
+
aria-expanded="false">Menu</button>
|
|
481
|
+
<div data-shadcn--navigation-menu-target="content" hidden>Content</div>
|
|
482
|
+
</li>
|
|
483
|
+
</ul>
|
|
484
|
+
</nav>
|
|
485
|
+
`
|
|
486
|
+
|
|
487
|
+
beforeEach(async () => {
|
|
488
|
+
const setup = await setupController(NavigationMenuController, timerHTML, 'shadcn--navigation-menu')
|
|
489
|
+
application = setup.application
|
|
490
|
+
element = setup.element
|
|
491
|
+
controller = setup.controller
|
|
492
|
+
})
|
|
493
|
+
|
|
494
|
+
test("clearTimers clears open timer", () => {
|
|
495
|
+
controller.openTimer = setTimeout(() => {}, 1000)
|
|
496
|
+
controller.clearTimers()
|
|
497
|
+
|
|
498
|
+
expect(controller.openTimer).toBeNull()
|
|
499
|
+
})
|
|
500
|
+
|
|
501
|
+
test("clearTimers clears close timer", () => {
|
|
502
|
+
controller.closeTimer = setTimeout(() => {}, 1000)
|
|
503
|
+
controller.clearTimers()
|
|
504
|
+
|
|
505
|
+
expect(controller.closeTimer).toBeNull()
|
|
506
|
+
})
|
|
507
|
+
})
|
|
508
|
+
|
|
509
|
+
describe("disconnect cleanup", () => {
|
|
510
|
+
const disconnectHTML = `
|
|
511
|
+
<nav data-controller="shadcn--navigation-menu"
|
|
512
|
+
data-shadcn--navigation-menu-open-index-value="-1">
|
|
513
|
+
<ul data-shadcn--navigation-menu-target="list">
|
|
514
|
+
<li data-shadcn--navigation-menu-target="item">
|
|
515
|
+
<button data-shadcn--navigation-menu-target="trigger" aria-expanded="false">Menu</button>
|
|
516
|
+
<div data-shadcn--navigation-menu-target="content" hidden>Content</div>
|
|
517
|
+
</li>
|
|
518
|
+
</ul>
|
|
519
|
+
</nav>
|
|
520
|
+
`
|
|
521
|
+
|
|
522
|
+
beforeEach(async () => {
|
|
523
|
+
const setup = await setupController(NavigationMenuController, disconnectHTML, 'shadcn--navigation-menu')
|
|
524
|
+
application = setup.application
|
|
525
|
+
element = setup.element
|
|
526
|
+
controller = setup.controller
|
|
527
|
+
})
|
|
528
|
+
|
|
529
|
+
test("closes all on disconnect", async () => {
|
|
530
|
+
controller.openItem(0)
|
|
531
|
+
await nextFrame()
|
|
532
|
+
|
|
533
|
+
controller.disconnect()
|
|
534
|
+
await nextFrame()
|
|
535
|
+
|
|
536
|
+
expect(controller.openIndexValue).toBe(-1)
|
|
537
|
+
})
|
|
538
|
+
|
|
539
|
+
test("clears timers on disconnect", () => {
|
|
540
|
+
controller.openTimer = setTimeout(() => {}, 1000)
|
|
541
|
+
controller.closeTimer = setTimeout(() => {}, 1000)
|
|
542
|
+
|
|
543
|
+
controller.disconnect()
|
|
544
|
+
|
|
545
|
+
expect(controller.openTimer).toBeNull()
|
|
546
|
+
expect(controller.closeTimer).toBeNull()
|
|
547
|
+
})
|
|
548
|
+
})
|
|
549
|
+
|
|
550
|
+
describe("viewport functionality", () => {
|
|
551
|
+
const viewportHTML = `
|
|
552
|
+
<nav data-controller="shadcn--navigation-menu"
|
|
553
|
+
data-shadcn--navigation-menu-open-index-value="-1">
|
|
554
|
+
<ul data-shadcn--navigation-menu-target="list">
|
|
555
|
+
<li data-shadcn--navigation-menu-target="item">
|
|
556
|
+
<button data-shadcn--navigation-menu-target="trigger" aria-expanded="false">Menu</button>
|
|
557
|
+
<div data-shadcn--navigation-menu-target="content" hidden style="width: 200px; height: 100px;">
|
|
558
|
+
<p>Content here</p>
|
|
559
|
+
</div>
|
|
560
|
+
</li>
|
|
561
|
+
</ul>
|
|
562
|
+
<div data-shadcn--navigation-menu-target="viewport" hidden></div>
|
|
563
|
+
</nav>
|
|
564
|
+
`
|
|
565
|
+
|
|
566
|
+
beforeEach(async () => {
|
|
567
|
+
const setup = await setupController(NavigationMenuController, viewportHTML, 'shadcn--navigation-menu')
|
|
568
|
+
application = setup.application
|
|
569
|
+
element = setup.element
|
|
570
|
+
controller = setup.controller
|
|
571
|
+
})
|
|
572
|
+
|
|
573
|
+
test("has viewport target", () => {
|
|
574
|
+
expect(controller.hasViewportTarget).toBe(true)
|
|
575
|
+
})
|
|
576
|
+
|
|
577
|
+
test("shows viewport when item opened", async () => {
|
|
578
|
+
controller.openItem(0)
|
|
579
|
+
await nextFrame()
|
|
580
|
+
|
|
581
|
+
expect(controller.viewportTarget.hidden).toBe(false)
|
|
582
|
+
})
|
|
583
|
+
|
|
584
|
+
test("sets viewport data-state to open", async () => {
|
|
585
|
+
controller.openItem(0)
|
|
586
|
+
await nextFrame()
|
|
587
|
+
|
|
588
|
+
expect(controller.viewportTarget.dataset.state).toBe("open")
|
|
589
|
+
})
|
|
590
|
+
|
|
591
|
+
test("copies content to viewport", async () => {
|
|
592
|
+
controller.openItem(0)
|
|
593
|
+
await nextFrame()
|
|
594
|
+
|
|
595
|
+
expect(controller.viewportTarget.innerHTML).toContain("Content here")
|
|
596
|
+
})
|
|
597
|
+
})
|
|
598
|
+
})
|