Skip to content

Commit fc71cf8

Browse files
authored
aria-disabled for Switch (#282)
1 parent e4264da commit fc71cf8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/ruby_ui/switch/switch.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@ def initialize(include_hidden: true, checked_value: "1", unchecked_value: "0", *
1212
def view_template
1313
label(
1414
role: "switch",
15-
class: "peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-50 bg-input has-[:checked]:bg-primary"
15+
class: [
16+
"peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors bg-input",
17+
"has-checked:bg-primary",
18+
"has-disabled:cursor-not-allowed has-disabled:opacity-50",
19+
"has-aria-disabled:cursor-not-allowed has-aria-disabled:opacity-50 has-aria-disabled:pointer-events-none",
20+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
21+
]
1622
) do
1723
input(type: "hidden", name: attrs[:name], value: @unchecked_value) if @include_hidden
24+
1825
input(**attrs.merge(type: "checkbox", class: "hidden peer", value: @checked_value))
1926

20-
span(class: "pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform translate-x-0 peer-checked:translate-x-5 ")
27+
span(class: [
28+
"pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform translate-x-0",
29+
"peer-checked:translate-x-5"
30+
])
2131
end
2232
end
2333
end

0 commit comments

Comments
 (0)