Skip to content

Commit b1f2bcd

Browse files
pierry01cirdes
andauthored
aria-disabled for Switch (#233)
Co-authored-by: Cirdes <[email protected]>
1 parent 07c0922 commit b1f2bcd

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

app/components/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

app/views/docs/switch.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ def view_template
2727
RUBY
2828
end
2929

30+
render Docs::VisualCodeExample.new(title: "Aria Disabled", context: self) do
31+
<<~RUBY
32+
Switch(name: "switch", aria: {disabled: "true"})
33+
RUBY
34+
end
35+
3036
render Docs::VisualCodeExample.new(title: "With flag include_hidden false", context: self) do
3137
<<~RUBY
3238
# Supports the creation of a hidden input to be used in forms inspired by the Ruby on Rails implementation of check_box. Default is true.

0 commit comments

Comments
 (0)