Class: Daisy::Navigation::TabsComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::Navigation::TabsComponent
- Defined in:
- app/components/daisy/navigation/tabs_component.rb
Overview
When using radio button tabs, the titles must be simple strings and cannot contain HTML elements or icons. Radio tabs also keep the browser's native radio-group keyboard behavior: arrow keys move the selection immediately (automatic activation), unlike JS-driven tabs below, where arrows only move focus and Enter/Space selects.
Link-mode tabs render as <a> elements when given an href, and
as <button> elements otherwise, so JavaScript-driven tabs remain
focusable and keyboard-activatable.
Tabs that have a content panel but no href are automatically
wired to the loco-tabs Stimulus controller, which implements the
ARIA tabs pattern with manual activation: a roving tabindex keeps
each tablist a single Tab stop, Left / Right / Home / End move focus
between tabs, and Enter / Space (or a click) activates the focused
tab. Register it once from the npm package:
application.register("loco-tabs", TabsController). The attributes
are inert if the controller is not registered.
Creates a tabbed navigation component that can be used either as links or radio buttons with associated content.
Defined Under Namespace
Classes: TabComponent
Constant Summary
Constants inherited from LocoMotion::BaseComponent
LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#radio ⇒ Object
readonly
Returns the value of attribute radio.
Attributes inherited from LocoMotion::BaseComponent
Instance Method Summary collapse
- #before_render ⇒ Object
-
#initialize(*args, **kws, &block) ⇒ TabsComponent
constructor
Create a new instance of the TabsComponent.
- #radio? ⇒ Boolean
Methods inherited from LocoMotion::BaseComponent
build, #component_ref, #config_option, #cssify, define_modifier, define_modifiers, define_part, define_parts, define_size, define_sizes, #empty_part_content, #inspect, #part, register_component_initializer, register_component_setup, #rendered_css, #rendered_data, #rendered_html, #rendered_stimulus_controllers, #rendered_tag_name, renders_many, renders_one, set_component_name, #set_loco_parent, #strip_spaces
Methods included from LocoMotion::Concerns::InspectableComponent
Constructor Details
#initialize(*args, **kws, &block) ⇒ TabsComponent
Create a new instance of the TabsComponent.
277 278 279 280 281 282 |
# File 'app/components/daisy/navigation/tabs_component.rb', line 277 def initialize(*args, **kws, &block) super @name = config_option(:name, "tabs-#{SecureRandom.uuid}") @radio = config_option(:radio, false) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
256 257 258 |
# File 'app/components/daisy/navigation/tabs_component.rb', line 256 def name @name end |
#radio ⇒ Object (readonly)
Returns the value of attribute radio.
256 257 258 |
# File 'app/components/daisy/navigation/tabs_component.rb', line 256 def radio @radio end |
Instance Method Details
#before_render ⇒ Object
284 285 286 287 288 289 290 291 292 |
# File 'app/components/daisy/navigation/tabs_component.rb', line 284 def before_render add_css(:component, "tabs") add_html(:component, { role: "tablist" }) # Radio tabs switch natively; link/button tablists get the loco-tabs # Stimulus controller for JS-driven switching. The attributes are # inert until the app registers the controller. add_stimulus_controller(:component, "loco-tabs") unless radio? end |
#radio? ⇒ Boolean
294 295 296 |
# File 'app/components/daisy/navigation/tabs_component.rb', line 294 def radio? radio end |