module NfgUi::Bootstrap::Utilities::Disableable
Allows components to have a disabled state when appropriate
Attributes
as[R]
Public Instance Methods
disabled()
click to toggle source
# File lib/nfg_ui/bootstrap/utilities/disableable.rb, line 10 def disabled options.fetch(:disabled, false) end
Private Instance Methods
assistive_html_attributes()
click to toggle source
Calls superclass method
# File lib/nfg_ui/bootstrap/utilities/disableable.rb, line 34 def assistive_html_attributes if disabled super.merge!(tabindex: '-1', **(tag_allows_for_disable_attribute?) ? { disabled: true } : {}) else super end end
css_classes()
click to toggle source
Calls superclass method
# File lib/nfg_ui/bootstrap/utilities/disableable.rb, line 16 def css_classes # when the tag does not take a disabled attribute we # assigne the disabled class [ super, ('disabled' if disabled && !tag_allows_for_disable_attribute?) ].join(' ').squish end
non_html_attribute_options()
click to toggle source
Calls superclass method
# File lib/nfg_ui/bootstrap/utilities/disableable.rb, line 25 def non_html_attribute_options # if tag accepts the disabled attribute # push it through, otherwise remove it from the # html options. We do this regardless of whether or not # disabled was actually set to ensure that those # tags that can't take a disabled option never receive it tag_allows_for_disable_attribute? ? super : super.push(:disabled) end
tag_allows_for_disable_attribute?()
click to toggle source
# File lib/nfg_ui/bootstrap/utilities/disableable.rb, line 43 def tag_allows_for_disable_attribute? [:button, :input, :fieldset, :optgroup, :option, :select, :textarea].include?(as) end