velvetkit 0.4.2 → 0.5.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 +4 -4
- data/CHANGELOG.md +127 -2
- data/lib/velvetkit/version.rb +1 -1
- data/registry/app/components/ui/accordion/trigger.rb +1 -1
- data/registry/app/components/ui/badge.rb +1 -1
- data/registry/app/components/ui/base.rb +2 -2
- data/registry/app/components/ui/button.rb +1 -1
- data/registry/app/components/ui/carousel.html.erb +7 -0
- data/registry/app/components/ui/carousel.rb +60 -0
- data/registry/app/components/ui/chart.html.erb +3 -3
- data/registry/app/components/ui/chart.rb +18 -10
- data/registry/app/components/ui/checkbox.html.erb +6 -0
- data/registry/app/components/ui/checkbox.rb +11 -4
- data/registry/app/components/ui/fieldset.html.erb +6 -0
- data/registry/app/components/ui/fieldset.rb +76 -0
- data/registry/app/components/ui/gallery/image.rb +14 -1
- data/registry/app/components/ui/gallery.html.erb +32 -3
- data/registry/app/components/ui/gallery.rb +46 -7
- data/registry/app/components/ui/link.rb +1 -1
- data/registry/app/components/ui/menu/item.rb +1 -1
- data/registry/app/components/ui/radio_group/item.html.erb +1 -1
- data/registry/app/components/ui/radio_group/item.rb +5 -1
- data/registry/app/components/ui/radio_group.html.erb +1 -1
- data/registry/app/components/ui/radio_group.rb +42 -2
- data/registry/app/components/ui/scrubber.html.erb +18 -0
- data/registry/app/components/ui/scrubber.rb +62 -0
- data/registry/app/components/ui/select.html.erb +1 -1
- data/registry/app/components/ui/select.rb +16 -1
- data/registry/app/components/ui/selection_bar.html.erb +7 -0
- data/registry/app/components/ui/selection_bar.rb +75 -0
- data/registry/app/components/ui/sidebar/group_label.rb +1 -1
- data/registry/app/components/ui/sidebar/inset.rb +5 -2
- data/registry/app/components/ui/sidebar/menu_button.rb +24 -9
- data/registry/app/components/ui/sidebar/menu_item.html.erb +1 -1
- data/registry/app/components/ui/sidebar/menu_item.rb +31 -5
- data/registry/app/components/ui/sidebar/menu_sub.rb +59 -0
- data/registry/app/components/ui/sidebar.html.erb +3 -3
- data/registry/app/components/ui/sidebar.rb +91 -13
- data/registry/app/components/ui/switch.rb +2 -2
- data/registry/app/components/ui/table/column.html.erb +1 -1
- data/registry/app/components/ui/table/column.rb +26 -2
- data/registry/app/components/ui/table/head.html.erb +1 -1
- data/registry/app/components/ui/table/head.rb +15 -2
- data/registry/app/components/ui/table/row.html.erb +1 -1
- data/registry/app/components/ui/table/row.rb +19 -5
- data/registry/app/components/ui/table.html.erb +2 -2
- data/registry/app/components/ui/table.rb +29 -4
- data/registry/app/components/ui/tabs/trigger.rb +1 -1
- data/registry/app/components/ui/toggle_group.html.erb +1 -1
- data/registry/app/components/ui/toggle_group.rb +26 -3
- data/registry/app/javascript/controllers/ui/carousel_controller.ts +63 -0
- data/registry/app/javascript/controllers/ui/file_field_controller.ts +1 -1
- data/registry/app/javascript/controllers/ui/gallery_controller.ts +52 -14
- data/registry/app/javascript/controllers/ui/scrubber_controller.ts +188 -0
- data/registry/app/javascript/controllers/ui/selection_bar_controller.ts +122 -0
- data/registry/app/javascript/controllers/ui/sidebar_controller.ts +102 -32
- data/registry/components.yml +11 -3
- data/registry/config/locales/velvetkit.en.yml +16 -0
- data/registry/icons/lucide/arrow-down.svg +16 -0
- data/registry/icons/lucide/arrow-up.svg +16 -0
- data/registry/icons/lucide/image.svg +17 -0
- data/registry/icons/lucide/star.svg +15 -0
- data/registry/icons/phosphor/arrow-down.svg +2 -0
- data/registry/icons/phosphor/arrow-up.svg +2 -0
- data/registry/icons/phosphor/image.svg +2 -0
- data/registry/icons/phosphor/star.svg +2 -0
- data/registry/icons/tabler/arrow-down.svg +18 -0
- data/registry/icons/tabler/arrow-up.svg +18 -0
- data/registry/icons/tabler/photo.svg +19 -0
- data/registry/icons/tabler/star.svg +16 -0
- data/registry/icons.yml +4 -0
- data/registry/test/components/previews/ui/carousel_preview/highlights.html.erb +17 -0
- data/registry/test/components/previews/ui/carousel_preview.rb +22 -0
- data/registry/test/components/previews/ui/chart_preview/whole_dollars.html.erb +19 -0
- data/registry/test/components/previews/ui/chart_preview.rb +7 -1
- data/registry/test/components/previews/ui/checkbox_preview/in_form.html.erb +2 -3
- data/registry/test/components/previews/ui/fieldset_preview/block_of_fields.html.erb +18 -0
- data/registry/test/components/previews/ui/fieldset_preview/groups.html.erb +14 -0
- data/registry/test/components/previews/ui/fieldset_preview/model_errors.html.erb +22 -0
- data/registry/test/components/previews/ui/fieldset_preview/playground.html.erb +5 -0
- data/registry/test/components/previews/ui/fieldset_preview.rb +24 -0
- data/registry/test/components/previews/ui/gallery_preview/grid.html.erb +25 -0
- data/registry/test/components/previews/ui/gallery_preview.rb +3 -0
- data/registry/test/components/previews/ui/scrubber_preview/default.html.erb +24 -0
- data/registry/test/components/previews/ui/scrubber_preview.rb +6 -0
- data/registry/test/components/previews/ui/selection_bar_preview/floating.html.erb +16 -0
- data/registry/test/components/previews/ui/selection_bar_preview/table.html.erb +26 -0
- data/registry/test/components/previews/ui/selection_bar_preview.rb +9 -0
- data/registry/test/components/previews/ui/sidebar_preview/_shell.html.erb +5 -4
- data/registry/test/components/previews/ui/sidebar_preview/pill_links.html.erb +52 -0
- data/registry/test/components/previews/ui/sidebar_preview.rb +3 -0
- data/registry/test/components/previews/ui/table_preview/selectable.html.erb +26 -0
- data/registry/test/components/previews/ui/table_preview/sortable.html.erb +20 -0
- data/registry/test/components/previews/ui/table_preview/sticky_header.html.erb +13 -0
- data/registry/test/components/previews/ui/table_preview.rb +9 -0
- data/registry/test/components/ui/button_test.rb +2 -2
- data/registry/test/components/ui/carousel_test.rb +38 -0
- data/registry/test/components/ui/chart_test.rb +20 -0
- data/registry/test/components/ui/checkbox_test.rb +11 -2
- data/registry/test/components/ui/fieldset_test.rb +119 -0
- data/registry/test/components/ui/gallery_test.rb +40 -5
- data/registry/test/components/ui/link_test.rb +1 -1
- data/registry/test/components/ui/number_input_test.rb +1 -1
- data/registry/test/components/ui/radio_group_test.rb +106 -0
- data/registry/test/components/ui/scrubber_test.rb +43 -0
- data/registry/test/components/ui/select_test.rb +21 -0
- data/registry/test/components/ui/selection_bar_test.rb +46 -0
- data/registry/test/components/ui/sidebar/menu_button_test.rb +9 -0
- data/registry/test/components/ui/sidebar_test.rb +79 -1
- data/registry/test/components/ui/switch_test.rb +4 -4
- data/registry/test/components/ui/toggle_group_test.rb +45 -0
- metadata +47 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<%# shape: :pill gives taller links, the current one filled in end to end. A
|
|
2
|
+
sub-menu opens under its link from the arrow beside it, and starts open
|
|
3
|
+
when one of its links is the current page. The footer stays at the bottom
|
|
4
|
+
of the frame, because the wrapper has a height. On a phone the trigger
|
|
5
|
+
opens the sidebar as a drawer over the page. %>
|
|
6
|
+
<div class="relative h-[600px] overflow-hidden rounded-lg border transform-gpu">
|
|
7
|
+
<%= render(UI::Sidebar::Wrapper.new(min_height: :none, class: "h-full overflow-y-auto")) do %>
|
|
8
|
+
<%= render(UI::Sidebar.new(id: "preview-sidebar-pill", collapsible: :icon)) do |sidebar| %>
|
|
9
|
+
<% sidebar.with_sidebar_header do %>
|
|
10
|
+
<div class="flex h-10 items-center gap-2 px-2 font-semibold"><%= render(UI::Icon.new(name: "image", size: :sm)) %><span class="group-data-[collapsible=icon]:hidden">Photos</span></div>
|
|
11
|
+
<% end %>
|
|
12
|
+
<% sidebar.with_sidebar_content do |content| %>
|
|
13
|
+
<% content.with_sidebar_group do |group| %>
|
|
14
|
+
<% group.with_menu do |menu| %>
|
|
15
|
+
<% menu.with_menu_item do |item| %>
|
|
16
|
+
<% item.with_menu_button("#", active: true, shape: :pill) do %><%= render(UI::Icon.new(name: "image")) %><span>Photos</span><% end %>
|
|
17
|
+
<% end %>
|
|
18
|
+
<% menu.with_menu_item do |item| %>
|
|
19
|
+
<% item.with_menu_button("#", shape: :pill) do %><%= render(UI::Icon.new(name: "star")) %><span>Favourites</span><% end %>
|
|
20
|
+
<% end %>
|
|
21
|
+
<% menu.with_menu_item(open: true) do |item| %>
|
|
22
|
+
<% item.with_menu_button("#", shape: :pill) do %><%= render(UI::Icon.new(name: "book-open")) %><span>Albums</span><% end %>
|
|
23
|
+
<% item.with_sub_menu(name: "Albums") do |sub| %>
|
|
24
|
+
<% %w[Coast\ walk Garden City\ at\ night].each do |album| %>
|
|
25
|
+
<% sub.with_item("#") { album } %>
|
|
26
|
+
<% end %>
|
|
27
|
+
<% end %>
|
|
28
|
+
<% end %>
|
|
29
|
+
<% menu.with_menu_item do |item| %>
|
|
30
|
+
<% item.with_menu_button("#", shape: :pill) do %><%= render(UI::Icon.new(name: "trash-2")) %><span>Bin</span><% end %>
|
|
31
|
+
<% end %>
|
|
32
|
+
<% end %>
|
|
33
|
+
<% end %>
|
|
34
|
+
<% end %>
|
|
35
|
+
<% sidebar.with_sidebar_footer do %>
|
|
36
|
+
<div class="space-y-2 px-2 pb-2 group-data-[collapsible=icon]:hidden">
|
|
37
|
+
<%= render(UI::Progress.new(value: 62, label: "Storage")) %>
|
|
38
|
+
<p class="text-xs text-muted-foreground">62 GB of 100 GB used</p>
|
|
39
|
+
</div>
|
|
40
|
+
<% end %>
|
|
41
|
+
<% end %>
|
|
42
|
+
<%= render(UI::Sidebar::Inset.new) do %>
|
|
43
|
+
<header class="flex h-14 shrink-0 items-center gap-2 border-b px-4">
|
|
44
|
+
<%= render(UI::Sidebar::Trigger.new(sidebar_id: "preview-sidebar-pill")) %>
|
|
45
|
+
<span class="text-sm font-medium">Photos</span>
|
|
46
|
+
</header>
|
|
47
|
+
<div class="grid grid-cols-3 gap-1 p-4 sm:grid-cols-4">
|
|
48
|
+
<% 16.times do %><div class="aspect-square rounded-sm bg-muted"></div><% end %>
|
|
49
|
+
</div>
|
|
50
|
+
<% end %>
|
|
51
|
+
<% end %>
|
|
52
|
+
</div>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<%# Each row has a box, and the header one chooses them all. The bar above
|
|
2
|
+
counts them and holds what to do with them; Shift-click chooses a run, and
|
|
3
|
+
Escape clears. The boxes belong to the "bulk" form, so the buttons post
|
|
4
|
+
them. %>
|
|
5
|
+
<%= form_tag "#", id: "bulk" %></form>
|
|
6
|
+
<div id="customers" class="max-w-2xl">
|
|
7
|
+
<%= render(UI::SelectionBar.new(for: "customers", label: "Selected customers", class: "rounded-t-md border")) do |bar| %>
|
|
8
|
+
<% bar.with_action do %><%= render(UI::Button.new(variant: :ghost, size: :sm, type: :submit, form: "bulk")) { "Export" } %><% end %>
|
|
9
|
+
<% bar.with_action do %><%= render(UI::Button.new(variant: :ghost, size: :sm, type: :submit, form: "bulk", class: "text-destructive")) { "Cancel plans" } %><% end %>
|
|
10
|
+
<% end %>
|
|
11
|
+
<%= render(UI::Table.new(selection: "ids[]", form: "bulk")) do |table| %>
|
|
12
|
+
<% table.with_head do |head| %>
|
|
13
|
+
<% head.with_column { "Customer" } %>
|
|
14
|
+
<% head.with_column { "Plan" } %>
|
|
15
|
+
<% head.with_column(align: :end) { "Seats" } %>
|
|
16
|
+
<% end %>
|
|
17
|
+
<% [ [ 1, "Aditi Rao", "Business", 24 ], [ 2, "Arjun Nair", "Team", 8 ], [ 3, "Chitra Menon", "Starter", 1 ],
|
|
18
|
+
[ 4, "Dev Patel", "Team", 12 ], [ 5, "Esha Iyer", "Business", 31 ] ].each do |id, name, plan, seats| %>
|
|
19
|
+
<% table.with_row(value: id, label: name) do |row| %>
|
|
20
|
+
<% row.with_cell(class: "font-medium") { name } %>
|
|
21
|
+
<% row.with_cell { plan } %>
|
|
22
|
+
<% row.with_cell(align: :end, class: "tabular-nums") { seats.to_s } %>
|
|
23
|
+
<% end %>
|
|
24
|
+
<% end %>
|
|
25
|
+
<% end %>
|
|
26
|
+
</div>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<%# Sorting is the server's job: each header links to the list sorted by it,
|
|
2
|
+
and says which way it's sorted now. Here it's sorted by seats, most first;
|
|
3
|
+
in an app, `sort` and `dir` come from params. %>
|
|
4
|
+
<% sort, dir = "seats", "desc" %>
|
|
5
|
+
<% rows = [ [ "Aditi Rao", 24 ], [ "Arjun Nair", 8 ], [ "Chitra Menon", 1 ], [ "Dev Patel", 12 ] ] %>
|
|
6
|
+
<% rows = rows.sort_by { |name, seats| sort == "customer" ? name : seats } %>
|
|
7
|
+
<% rows.reverse! if dir == "desc" %>
|
|
8
|
+
<% link = ->(column) { "?sort=#{column}&dir=#{sort == column && dir == 'asc' ? 'desc' : 'asc'}" } %>
|
|
9
|
+
<%= render(UI::Table.new(class: "max-w-lg")) do |table| %>
|
|
10
|
+
<% table.with_head do |head| %>
|
|
11
|
+
<% head.with_column(sort_href: link.("customer"), sorted: (dir if sort == "customer")) { "Customer" } %>
|
|
12
|
+
<% head.with_column(sort_href: link.("seats"), sorted: (dir if sort == "seats"), align: :end) { "Seats" } %>
|
|
13
|
+
<% end %>
|
|
14
|
+
<% rows.each do |name, seats| %>
|
|
15
|
+
<% table.with_row do |row| %>
|
|
16
|
+
<% row.with_cell { name } %>
|
|
17
|
+
<% row.with_cell(align: :end, class: "tabular-nums") { seats.to_s } %>
|
|
18
|
+
<% end %>
|
|
19
|
+
<% end %>
|
|
20
|
+
<% end %>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<%# The rows scroll in their own box, under the header. %>
|
|
2
|
+
<%= render(UI::Table.new(sticky_header: true, max_height: "16rem", class: "max-w-lg")) do |table| %>
|
|
3
|
+
<% table.with_head do |head| %>
|
|
4
|
+
<% head.with_column { "Invoice" } %>
|
|
5
|
+
<% head.with_column(align: :end) { "Amount" } %>
|
|
6
|
+
<% end %>
|
|
7
|
+
<% 20.times do |i| %>
|
|
8
|
+
<% table.with_row do |row| %>
|
|
9
|
+
<% row.with_cell { "INV-#{1040 + i}" } %>
|
|
10
|
+
<% row.with_cell(align: :end, class: "tabular-nums") { "$#{(i * 37 % 90 + 10) * 10}.00" } %>
|
|
11
|
+
<% end %>
|
|
12
|
+
<% end %>
|
|
13
|
+
<% end %>
|
|
@@ -9,4 +9,13 @@ class UI::TablePreview < ViewComponent::Preview
|
|
|
9
9
|
|
|
10
10
|
# @label With Caption And Selection
|
|
11
11
|
def with_caption; render_with_template; end
|
|
12
|
+
|
|
13
|
+
# @label Sortable Columns
|
|
14
|
+
def sortable; render_with_template; end
|
|
15
|
+
|
|
16
|
+
# @label Rows to Select, With a Selection Bar
|
|
17
|
+
def selectable; render_with_template; end
|
|
18
|
+
|
|
19
|
+
# @label Sticky Header
|
|
20
|
+
def sticky_header; render_with_template; end
|
|
12
21
|
end
|
|
@@ -23,8 +23,8 @@ class UI::ButtonTest < ViewComponent::TestCase
|
|
|
23
23
|
assert_includes classes, "bg-destructive"
|
|
24
24
|
refute_includes classes, "bg-primary"
|
|
25
25
|
# destructive variant overrides the default focus ring color
|
|
26
|
-
assert_includes classes, "focus:ring-destructive"
|
|
27
|
-
refute_includes classes, "focus:ring-primary"
|
|
26
|
+
assert_includes classes, "focus-visible:ring-destructive"
|
|
27
|
+
refute_includes classes, "focus-visible:ring-primary"
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def test_renders_outline_variant
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::CarouselTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def render_carousel(**opts)
|
|
10
|
+
render_inline(UI::Carousel.new(label: "Highlights", **opts)) do |carousel|
|
|
11
|
+
carousel.with_item { "Coast" }
|
|
12
|
+
carousel.with_item { "Garden" }
|
|
13
|
+
carousel.with_item { "City" }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_a_named_region_of_snapping_items
|
|
18
|
+
render_carousel(item_class: "w-64")
|
|
19
|
+
region = page.find("[role=region][aria-roledescription=carousel][aria-label=Highlights][data-controller='ui--carousel']")
|
|
20
|
+
assert_includes region.find("ul")[:class], "snap-x"
|
|
21
|
+
assert_equal %w[Coast Garden City], page.all("ul li").map(&:text)
|
|
22
|
+
assert_includes page.all("ul li").first[:class], "w-64"
|
|
23
|
+
assert_includes page.all("ul li").first[:class], "snap-start"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_buttons_start_hidden_and_control_the_strip
|
|
27
|
+
render_carousel
|
|
28
|
+
track = page.find("ul")[:id]
|
|
29
|
+
assert_selector "button[aria-label=Previous][hidden][aria-controls='#{track}'][data-action='ui--carousel#previous']", visible: :all
|
|
30
|
+
assert_selector "button[aria-label=Next][hidden][aria-controls='#{track}'] svg[data-icon='chevron-right']", visible: :all
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_gap_class_and_attributes
|
|
34
|
+
render_carousel(gap: 6, class: "mt-4", id: "highlights")
|
|
35
|
+
assert_selector "#highlights.mt-4"
|
|
36
|
+
assert_includes page.find("ul")[:class], "gap-6"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -96,6 +96,26 @@ class UI::ChartTest < ViewComponent::TestCase
|
|
|
96
96
|
assert_selector "td", text: "41.5%", visible: :all
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
+
def test_precision_sets_the_decimals
|
|
100
|
+
render_chart(format: :currency, precision: 0)
|
|
101
|
+
assert_equal [ "$1,200", "$1,501", "$900" ], config["series"].first["text"]
|
|
102
|
+
render_chart(precision: 1, series: [ { name: "Load", data: [ 1234.56, 2, 3 ] } ])
|
|
103
|
+
assert_selector "td", text: "1,234.6", visible: :all
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def test_show_data_false_keeps_the_table_for_screen_readers
|
|
107
|
+
render_chart(show_data: false)
|
|
108
|
+
assert_no_selector "details", visible: :all
|
|
109
|
+
assert_no_selector "summary", visible: :all
|
|
110
|
+
assert_selector "div.sr-only table td", text: "1,200", visible: :all
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def test_a_pie_sits_beside_its_legend_by_its_own_width
|
|
114
|
+
render_chart(type: :donut, series: [ { name: "Plan", data: [ 1, 2, 3 ] } ])
|
|
115
|
+
assert_includes page.find("[data-slot='chart']")[:class], "@container"
|
|
116
|
+
assert_selector "div.\\@md\\:flex-row"
|
|
117
|
+
end
|
|
118
|
+
|
|
99
119
|
def test_missing_values_leave_a_gap
|
|
100
120
|
render_chart(series: [ { name: "Sales", data: [ 1, nil, 3 ] } ])
|
|
101
121
|
assert_nil config["series"].first["data"][1]
|
|
@@ -77,7 +77,7 @@ class UI::CheckboxTest < ViewComponent::TestCase
|
|
|
77
77
|
def test_check_overlay_span_present_with_peer_checked_class
|
|
78
78
|
render_inline(UI::Checkbox.new(name: "test"))
|
|
79
79
|
wrapper = page.find(".relative.inline-flex")
|
|
80
|
-
overlay = wrapper.
|
|
80
|
+
overlay = wrapper.all("span.pointer-events-none").first
|
|
81
81
|
classes = overlay[:class].split
|
|
82
82
|
assert_includes classes, "peer-checked:opacity-100"
|
|
83
83
|
assert_includes classes, "opacity-0"
|
|
@@ -85,11 +85,20 @@ class UI::CheckboxTest < ViewComponent::TestCase
|
|
|
85
85
|
|
|
86
86
|
def test_check_icon_inside_overlay
|
|
87
87
|
render_inline(UI::Checkbox.new(name: "test"))
|
|
88
|
-
overlay = page.
|
|
88
|
+
overlay = page.all("span.pointer-events-none").first
|
|
89
89
|
icon = overlay.find("svg", visible: :all)
|
|
90
90
|
assert icon.matches_css?("[data-icon='check']")
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
+
# Script sets `indeterminate` on "select all" when some rows are chosen.
|
|
94
|
+
def test_a_partly_checked_box_shows_a_dash
|
|
95
|
+
render_inline(UI::Checkbox.new(name: "test"))
|
|
96
|
+
assert_includes page.find("input")[:class], "indeterminate:bg-primary"
|
|
97
|
+
dash = page.all("span.pointer-events-none").last
|
|
98
|
+
assert_includes dash[:class].split, "peer-indeterminate:opacity-100"
|
|
99
|
+
assert dash.find("svg", visible: :all).matches_css?("[data-icon='minus']")
|
|
100
|
+
end
|
|
101
|
+
|
|
93
102
|
def test_user_class_override_via_tailwind_merge
|
|
94
103
|
render_inline(UI::Checkbox.new(name: "test", class: "border-red-500"))
|
|
95
104
|
input = page.find("input[type='checkbox']")
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::FieldsetTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
Settings = Struct.new(:channels) do
|
|
10
|
+
include ActiveModel::Validations
|
|
11
|
+
def self.model_name = ActiveModel::Name.new(self, nil, "Settings")
|
|
12
|
+
validates :channels, presence: true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def form_builder_for(record)
|
|
16
|
+
ActionView::Helpers::FormBuilder.new(:settings, record, vc_test_controller.view_context, {})
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_renders_a_fieldset_named_by_its_legend
|
|
20
|
+
render_inline(UI::Fieldset.new(legend: "Notifications", id: "notify")) { "controls" }
|
|
21
|
+
assert_selector "fieldset#notify[aria-labelledby='notify-legend']", text: "controls"
|
|
22
|
+
assert_selector "fieldset > legend#notify-legend:first-child", text: "Notifications"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_hint_and_error_describe_the_group
|
|
26
|
+
render_inline(UI::Fieldset.new(legend: "Plan", hint: "Change it any time.", error: "Choose a plan", id: "plan"))
|
|
27
|
+
assert_selector "fieldset[aria-describedby='plan-hint plan-error']"
|
|
28
|
+
assert_selector "p#plan-hint", text: "Change it any time."
|
|
29
|
+
assert_selector "p#plan-error.text-destructive", text: "Choose a plan"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_hint_comes_before_the_controls_and_the_error_after
|
|
33
|
+
render_inline(UI::Fieldset.new(legend: "Plan", hint: "Hint", error: "Error")) { "<span>controls</span>".html_safe }
|
|
34
|
+
assert_equal %w[legend p span p], page.all("fieldset > *").map(&:tag_name)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_makes_an_id_when_given_none
|
|
38
|
+
render_inline(UI::Fieldset.new(legend: "Plan", hint: "Hint"))
|
|
39
|
+
id = page.find("fieldset")[:id]
|
|
40
|
+
assert id.start_with?("ui-fieldset-")
|
|
41
|
+
assert_selector "legend##{id}-legend"
|
|
42
|
+
assert_selector "p##{id}-hint"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_nothing_to_describe_means_no_aria_describedby
|
|
46
|
+
render_inline(UI::Fieldset.new(legend: "Plan"))
|
|
47
|
+
assert_no_selector "fieldset[aria-describedby]"
|
|
48
|
+
assert_no_selector "p"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_required_marks_the_legend
|
|
52
|
+
render_inline(UI::Fieldset.new(legend: "Plan", required: true))
|
|
53
|
+
assert_selector "legend span.text-destructive", text: "*"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_disabled_disables_the_fieldset
|
|
57
|
+
render_inline(UI::Fieldset.new(legend: "Plan", disabled: true))
|
|
58
|
+
assert_selector "fieldset[disabled]"
|
|
59
|
+
assert_selector "legend.text-muted-foreground"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_a_plain_group_takes_no_required_or_invalid
|
|
63
|
+
render_inline(UI::Fieldset.new(legend: "Plan", required: true, error: "Choose one"))
|
|
64
|
+
assert_no_selector "fieldset[aria-required]"
|
|
65
|
+
assert_no_selector "fieldset[aria-invalid]"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_a_radiogroup_is_required_and_invalid
|
|
69
|
+
render_inline(UI::Fieldset.new(legend: "Plan", required: true, error: true, role: "radiogroup"))
|
|
70
|
+
assert_selector "fieldset[role='radiogroup'][aria-required='true'][aria-invalid='true']"
|
|
71
|
+
assert_no_selector "p.text-destructive"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_wrap_only_with_something_to_show
|
|
75
|
+
assert UI::Fieldset.new(legend: "Plan").wrap?
|
|
76
|
+
assert UI::Fieldset.new(legend: false, hint: "Hint").wrap?
|
|
77
|
+
assert UI::Fieldset.new(legend: false, error: "Error").wrap?
|
|
78
|
+
refute UI::Fieldset.new(legend: false).wrap?
|
|
79
|
+
refute UI::Fieldset.new.wrap?
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_form_binding_names_it_and_shows_the_models_errors
|
|
83
|
+
render_inline(UI::Fieldset.new(form: form_builder_for(Settings.new([]).tap(&:validate)), field: :channels, id: "ch"))
|
|
84
|
+
assert_selector "legend", text: "Channels"
|
|
85
|
+
assert_selector "p#ch-error", text: "Channels can't be blank"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_legend_overrides_the_attribute_name_and_false_drops_it
|
|
89
|
+
form = form_builder_for(Settings.new([]))
|
|
90
|
+
render_inline(UI::Fieldset.new(form: form, field: :channels, legend: "Where to notify you"))
|
|
91
|
+
assert_selector "legend", text: "Where to notify you"
|
|
92
|
+
render_inline(UI::Fieldset.new(form: form, field: :channels, legend: false))
|
|
93
|
+
assert_no_selector "legend"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_user_class_and_attrs_pass_through
|
|
97
|
+
render_inline(UI::Fieldset.new(legend: "Plan", class: "gap-6", data: { testid: "plan" }, aria: { label: "Billing plan" }))
|
|
98
|
+
fieldset = page.find("fieldset[data-testid='plan'][aria-label='Billing plan']")
|
|
99
|
+
assert_includes fieldset[:class].split, "gap-6"
|
|
100
|
+
refute_includes fieldset[:class].split, "gap-3"
|
|
101
|
+
assert fieldset[:"aria-labelledby"].present?
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_never_an_empty_legend
|
|
105
|
+
render_inline(UI::Fieldset.new(legend: true)) { "x" }
|
|
106
|
+
assert_no_selector "legend"
|
|
107
|
+
assert_no_selector "fieldset[aria-labelledby]"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_your_aria_describedby_adds_to_the_hint_and_error
|
|
111
|
+
render_inline(UI::Fieldset.new(legend: "Plan", hint: "Hint", id: "plan", aria: { describedby: "terms" }))
|
|
112
|
+
assert_selector "fieldset[aria-describedby='plan-hint terms']"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test_a_long_legend_has_room_to_wrap
|
|
116
|
+
render_inline(UI::Fieldset.new(legend: "Plan"))
|
|
117
|
+
assert_includes page.find("legend")[:class].split, "leading-snug"
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -95,7 +95,7 @@ class UI::GalleryTest < ViewComponent::TestCase
|
|
|
95
95
|
render_gallery
|
|
96
96
|
assert_selector "dialog .start-4.top-4 button[aria-label='Zoom in']", visible: :all
|
|
97
97
|
assert_selector "dialog .start-4.top-4 button[aria-label='Zoom out']", visible: :all
|
|
98
|
-
assert_selector "dialog
|
|
98
|
+
assert_selector "dialog .end-4.top-4 button[aria-label='Close']", visible: :all
|
|
99
99
|
assert_selector "dialog button.start-4.top-1\\/2[aria-label='Previous image']", visible: :all
|
|
100
100
|
assert_selector "dialog button.end-4.top-1\\/2[aria-label='Next image']", visible: :all
|
|
101
101
|
end
|
|
@@ -175,18 +175,53 @@ class UI::GalleryTest < ViewComponent::TestCase
|
|
|
175
175
|
|
|
176
176
|
def test_buttons_keep_the_kits_focus_ring
|
|
177
177
|
render_gallery
|
|
178
|
-
assert_selector "button[aria-label='Show image 1'].focus\\:ring-primary"
|
|
179
|
-
assert_selector "button[aria-label='Next image'].focus\\:ring-primary", count: 1, visible: :all
|
|
178
|
+
assert_selector "button[aria-label='Show image 1'].focus-visible\\:ring-primary"
|
|
179
|
+
assert_selector "button[aria-label='Next image'].focus-visible\\:ring-primary", count: 1, visible: :all
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
def test_overlay_buttons_ring_in_white_to_show_on_the_dark_backdrop
|
|
183
183
|
render_gallery
|
|
184
|
-
assert_selector "dialog button[aria-label='Next image'].focus\\:ring-white", visible: :all
|
|
185
|
-
assert_selector "dialog button[aria-label='Close'].focus\\:ring-white", visible: :all
|
|
184
|
+
assert_selector "dialog button[aria-label='Next image'].focus-visible\\:ring-white", visible: :all
|
|
185
|
+
assert_selector "dialog button[aria-label='Close'].focus-visible\\:ring-white", visible: :all
|
|
186
186
|
end
|
|
187
187
|
|
|
188
188
|
def test_class_and_html_attributes_pass_through
|
|
189
189
|
render_gallery(class: "max-w-md", id: "photos", data: { foo: "bar" })
|
|
190
190
|
assert_selector "#photos.max-w-md[data-foo='bar'][data-controller='ui--gallery']"
|
|
191
191
|
end
|
|
192
|
+
|
|
193
|
+
def render_grid
|
|
194
|
+
render_inline(UI::Gallery.new(strip: false, label: "Photos")) do |gallery|
|
|
195
|
+
gallery.with_image(src: "/coast.jpg", alt: "Coast", zoom_src: "/coast-big.jpg") do |image|
|
|
196
|
+
image.with_info { "Taken in May" }
|
|
197
|
+
image.with_action { "<button>Favourite</button>".html_safe }
|
|
198
|
+
end
|
|
199
|
+
gallery.with_image(src: "/garden.jpg", alt: "Garden")
|
|
200
|
+
gallery.trigger(0, class: "aspect-square") { "<img src='/coast-sm.jpg' alt=''>".html_safe } +
|
|
201
|
+
gallery.trigger(1) { "<img src='/garden-sm.jpg' alt=''>".html_safe }
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def test_without_a_strip_the_page_opens_each_image
|
|
206
|
+
render_grid
|
|
207
|
+
assert_no_selector "[data-ui--gallery-target='track']", visible: :all
|
|
208
|
+
assert_no_selector "button[aria-label='Show image 1']", visible: :all
|
|
209
|
+
assert_selector "button.aspect-square[aria-label='Open Coast'][aria-haspopup=dialog][data-action='ui--gallery#open'][data-ui--gallery-index-param='0'][data-ui--gallery-target=trigger] img"
|
|
210
|
+
assert_selector "button[aria-label='Open Garden'][data-ui--gallery-index-param='1']"
|
|
211
|
+
assert_selector "li[data-ui--gallery-target=slide][data-zoom-src='/coast-big.jpg'][data-alt=Coast]", visible: :all
|
|
212
|
+
assert_selector "dialog button[aria-label='Next image']", visible: :all
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def test_info_and_actions_show_in_the_overlay_for_their_image
|
|
216
|
+
render_grid
|
|
217
|
+
toggle = page.find("dialog button[aria-label=Info][aria-expanded=false][data-action='ui--gallery#toggleInfo']", visible: :all)
|
|
218
|
+
panel = page.find("dialog aside##{toggle[:"aria-controls"]}[hidden]", visible: :all)
|
|
219
|
+
assert_equal "Taken in May", panel.find("[data-ui--gallery-target=perImage][data-index='0']", visible: :all).text(:all)
|
|
220
|
+
assert_selector "dialog [data-ui--gallery-target=perImage][data-index='0'] button", text: "Favourite", visible: :all
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def test_no_info_button_when_no_image_has_info
|
|
224
|
+
render_gallery
|
|
225
|
+
assert_no_selector "button[aria-label=Info]", visible: :all
|
|
226
|
+
end
|
|
192
227
|
end
|
|
@@ -43,7 +43,7 @@ class UI::LinkTest < ViewComponent::TestCase
|
|
|
43
43
|
link = page.find("a", text: "Delete")
|
|
44
44
|
classes = link[:class].split
|
|
45
45
|
assert_includes classes, "bg-destructive"
|
|
46
|
-
assert_includes classes, "focus:ring-destructive"
|
|
46
|
+
assert_includes classes, "focus-visible:ring-destructive"
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def test_size_sm
|
|
@@ -47,7 +47,7 @@ class UI::NumberInputTest < ViewComponent::TestCase
|
|
|
47
47
|
|
|
48
48
|
def test_buttons_keep_the_kits_focus_ring
|
|
49
49
|
render_input
|
|
50
|
-
assert_selector "button.focus\\:ring-2.focus\\:ring-primary.focus\\:z-10", count: 2
|
|
50
|
+
assert_selector "button.focus-visible\\:ring-2.focus-visible\\:ring-primary.focus\\:z-10", count: 2
|
|
51
51
|
assert_no_selector "button.focus\\:ring-0"
|
|
52
52
|
assert_no_selector "[data-slot='input-group'].overflow-hidden"
|
|
53
53
|
end
|
|
@@ -136,4 +136,110 @@ class UI::RadioGroupTest < ViewComponent::TestCase
|
|
|
136
136
|
assert_includes classes, "peer"
|
|
137
137
|
assert_includes classes, "appearance-none"
|
|
138
138
|
end
|
|
139
|
+
|
|
140
|
+
Account = Struct.new(:plan, :seats) do
|
|
141
|
+
include ActiveModel::Validations
|
|
142
|
+
def self.model_name = ActiveModel::Name.new(self, nil, "Account")
|
|
143
|
+
validates :plan, presence: true
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def form_builder_for(record)
|
|
147
|
+
ActionView::Helpers::FormBuilder.new(:account, record, vc_test_controller.view_context, {})
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def test_a_legend_makes_the_fieldset_the_radiogroup
|
|
151
|
+
render_inline(UI::RadioGroup.new(name: "plan", legend: "Plan", hint: "Change it any time.", required: true)) do |rg|
|
|
152
|
+
rg.with_item(value: "free", label: "Free")
|
|
153
|
+
end
|
|
154
|
+
fieldset = page.find("fieldset[role='radiogroup'][aria-required='true']")
|
|
155
|
+
assert_equal "#{fieldset[:id]}-legend", fieldset[:"aria-labelledby"]
|
|
156
|
+
assert_equal "#{fieldset[:id]}-hint", fieldset[:"aria-describedby"]
|
|
157
|
+
assert_selector "legend", text: "Plan"
|
|
158
|
+
assert_selector "[role='radiogroup']", count: 1
|
|
159
|
+
assert_selector "fieldset > div.flex-col input[type='radio'][name='plan'][required]"
|
|
160
|
+
assert_selector "span.text-destructive", text: "*", count: 1
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def test_without_a_legend_hint_or_error_it_is_unchanged
|
|
164
|
+
render_inline(UI::RadioGroup.new(name: "plan")) { |rg| rg.with_item(value: "free") }
|
|
165
|
+
assert_no_selector "fieldset"
|
|
166
|
+
assert_selector "div[role='radiogroup']"
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def test_error_marks_the_group_invalid
|
|
170
|
+
render_inline(UI::RadioGroup.new(name: "plan", legend: "Plan", error: "Choose a plan")) { |rg| rg.with_item(value: "free") }
|
|
171
|
+
fieldset = page.find("fieldset[aria-invalid='true']")
|
|
172
|
+
assert_selector "p##{fieldset[:id]}-error", text: "Choose a plan"
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def test_class_and_attrs_stay_on_the_radios_container
|
|
176
|
+
render_inline(UI::RadioGroup.new(name: "plan", legend: "Plan", id: "plans", class: "flex-row", data: { testid: "plans" })) do |rg|
|
|
177
|
+
rg.with_item(value: "free")
|
|
178
|
+
end
|
|
179
|
+
assert_selector "fieldset > div#plans.flex-row[data-testid='plans']"
|
|
180
|
+
assert_no_selector "fieldset[data-testid]"
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def test_form_builder_names_and_values
|
|
184
|
+
render_inline(UI::RadioGroup.new(form: form_builder_for(Account.new("pro")), field: :plan)) do |rg|
|
|
185
|
+
rg.with_item(value: "free", label: "Free")
|
|
186
|
+
rg.with_item(value: "pro", label: "Pro")
|
|
187
|
+
end
|
|
188
|
+
assert_selector "input[name='account[plan]']", count: 2
|
|
189
|
+
assert page.find("input[value='pro']").checked?
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def test_values_compare_as_strings
|
|
193
|
+
render_inline(UI::RadioGroup.new(form: form_builder_for(Account.new(nil, 5)), field: :seats)) do |rg|
|
|
194
|
+
rg.with_item(value: 5, label: "Five")
|
|
195
|
+
end
|
|
196
|
+
assert page.find("input[value='5']").checked?
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def test_a_bound_group_shows_the_models_error_without_growing_a_legend
|
|
200
|
+
render_inline(UI::RadioGroup.new(form: form_builder_for(Account.new(nil).tap(&:validate)), field: :plan)) do |rg|
|
|
201
|
+
rg.with_item(value: "free", label: "Free")
|
|
202
|
+
end
|
|
203
|
+
assert_selector "fieldset[role='radiogroup'][aria-invalid='true']"
|
|
204
|
+
assert_selector "p.text-destructive", text: "Plan can't be blank"
|
|
205
|
+
assert_no_selector "legend"
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def test_renders_no_whitespace_around_itself
|
|
209
|
+
render_inline(UI::RadioGroup.new(name: "plan")) { |rg| rg.with_item(value: "free") }
|
|
210
|
+
assert rendered_content.start_with?("<div"), rendered_content[0, 20].inspect
|
|
211
|
+
render_inline(UI::RadioGroup.new(name: "plan", legend: "Plan")) { |rg| rg.with_item(value: "free") }
|
|
212
|
+
assert rendered_content.start_with?("<fieldset"), rendered_content[0, 20].inspect
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def test_a_blank_legend_is_no_legend
|
|
216
|
+
render_inline(UI::RadioGroup.new(form: form_builder_for(Account.new("pro")), field: :plan, legend: "")) do |rg|
|
|
217
|
+
rg.with_item(value: "free")
|
|
218
|
+
end
|
|
219
|
+
assert_no_selector "fieldset"
|
|
220
|
+
assert_no_selector "legend"
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def test_legend_true_uses_the_attribute_name
|
|
224
|
+
render_inline(UI::RadioGroup.new(form: form_builder_for(Account.new("pro")), field: :plan, legend: true)) do |rg|
|
|
225
|
+
rg.with_item(value: "free")
|
|
226
|
+
end
|
|
227
|
+
assert_selector "legend", text: "Plan"
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def test_your_aria_attributes_move_to_the_fieldset
|
|
231
|
+
render_inline(UI::RadioGroup.new(name: "plan", hint: "Change it any time.", aria: { label: "Billing plan" })) do |rg|
|
|
232
|
+
rg.with_item(value: "free")
|
|
233
|
+
end
|
|
234
|
+
assert_selector "fieldset[role='radiogroup'][aria-label='Billing plan']"
|
|
235
|
+
assert_no_selector "div[aria-label]"
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def test_error_false_hides_the_models_error
|
|
239
|
+
render_inline(UI::RadioGroup.new(form: form_builder_for(Account.new(nil).tap(&:validate)), field: :plan, error: false)) do |rg|
|
|
240
|
+
rg.with_item(value: "free")
|
|
241
|
+
end
|
|
242
|
+
assert_no_selector "fieldset"
|
|
243
|
+
assert_selector "div[role='radiogroup']"
|
|
244
|
+
end
|
|
139
245
|
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::ScrubberTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def render_scrubber(**opts)
|
|
10
|
+
render_inline(UI::Scrubber.new(label: "Jump to a date", for: "library", **opts)) do |scrubber|
|
|
11
|
+
scrubber.with_mark(href: "#2026-03", label: "March 2026", major: "2026")
|
|
12
|
+
scrubber.with_mark(href: "#2026-02", label: "February 2026")
|
|
13
|
+
scrubber.with_mark(href: "#2025-12", label: "December 2025", major: "2025")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_a_named_nav_watching_what_scrolls
|
|
18
|
+
render_scrubber
|
|
19
|
+
nav = page.find("nav[aria-label='Jump to a date'][data-controller='ui--scrubber']")
|
|
20
|
+
assert_equal "library", nav[:"data-ui--scrubber-for-value"]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_each_mark_links_to_its_heading_and_only_one_is_a_tab_stop
|
|
24
|
+
render_scrubber
|
|
25
|
+
marks = page.all("a[data-ui--scrubber-target=mark]", visible: :all)
|
|
26
|
+
assert_equal %w[#2026-03 #2026-02 #2025-12], marks.map { |mark| mark[:href] }
|
|
27
|
+
assert_equal [ "March 2026", "February 2026", "December 2025" ], marks.map { |mark| mark[:"aria-label"] }
|
|
28
|
+
assert_equal %w[0 -1 -1], marks.map { |mark| mark[:tabindex] }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_majors_show_their_text_and_the_rest_are_dots
|
|
32
|
+
render_scrubber
|
|
33
|
+
assert_selector "a[data-major=true]", text: "2026", visible: :all
|
|
34
|
+
assert_selector "a[data-major=false] span.rounded-full", visible: :all
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_the_rail_drags_and_the_tip_and_line_are_hidden_from_screen_readers
|
|
38
|
+
render_scrubber(class: "fixed end-0")
|
|
39
|
+
assert_selector "nav.fixed.end-0 [data-ui--scrubber-target=rail][data-action*='pointerdown->ui--scrubber#grab']"
|
|
40
|
+
assert_selector "[data-ui--scrubber-target=thumb][aria-hidden=true]", visible: :all
|
|
41
|
+
assert_selector "[data-ui--scrubber-target=tip][aria-hidden=true]", visible: :all
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -90,6 +90,27 @@ class UI::SelectTest < ViewComponent::TestCase
|
|
|
90
90
|
|
|
91
91
|
# --- label, states, sizes ---------------------------------------------
|
|
92
92
|
|
|
93
|
+
def test_aria_label_names_the_visible_button_not_the_hidden_select
|
|
94
|
+
render_inline(UI::Select.new(name: "sort", options: TEAMS, "aria-label": "Sort by"))
|
|
95
|
+
assert_equal "Sort by", trigger["aria-label"]
|
|
96
|
+
assert_equal trigger[:id], listbox["aria-labelledby"]
|
|
97
|
+
assert_nil native["aria-label"]
|
|
98
|
+
assert_equal "true", native["aria-hidden"]
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def test_the_aria_hash_names_the_button_too
|
|
102
|
+
render_inline(UI::Select.new(name: "sort", options: TEAMS, aria: { label: "Sort by" }))
|
|
103
|
+
assert_equal "Sort by", trigger["aria-label"]
|
|
104
|
+
render_inline(UI::Select.new(name: "sort", options: TEAMS, "aria-labelledby": "heading"))
|
|
105
|
+
assert_equal "heading", trigger["aria-labelledby"]
|
|
106
|
+
assert_nil native["aria-labelledby"]
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_other_attributes_still_reach_the_native_select
|
|
110
|
+
render_inline(UI::Select.new(name: "sort", options: TEAMS, "aria-label": "Sort by", data: { testid: "s" }))
|
|
111
|
+
assert_equal "s", native["data-testid"]
|
|
112
|
+
end
|
|
113
|
+
|
|
93
114
|
def test_label_is_associated_with_the_trigger
|
|
94
115
|
render_inline(UI::Select.new(name: "section", options: TEAMS, label: "Team"))
|
|
95
116
|
assert_equal trigger[:id], page.find("label")[:for]
|