Class: Spark::Nav::Tree

Inherits:
Component::Base show all
Defined in:
app/components/spark/nav/tree.rb,
app/components/spark/nav/tree/group.rb

Defined Under Namespace

Classes: Group

Instance Method Summary collapse

Methods inherited from Component::Base

#selector, #to_s, #unique_id

Constructor Details

#initializeTree

Returns a new instance of Tree.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/components/spark/nav/tree.rb', line 22

def initialize(*)
  super

  classname.base = "nav-tree"
  data.add(tree: @id)
  aria.add(label: @label)
  tag_attrs.add(role: :tree)

  # Group icon should inherit default size
  set_element_attribute_default(:item, icon_size: @icon_size)
  set_element_attribute_default(:group, icon_size: @group_icon_size || @icon_size)
end

Instance Method Details

#active_itemObject



45
46
47
48
49
50
# File 'app/components/spark/nav/tree.rb', line 45

def active_item
  item = items.find(&:active?)
  # If the item is a group check return its active_item
  item = item.active_item if item.respond_to?(:active_item)
  item
end

#group_expanded?(node) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
# File 'app/components/spark/nav/tree.rb', line 35

def group_expanded?(node)
  @_cookie ||= begin
    view_context.parse_cookie( @id )
  rescue
    nil
  end

  @_cookie && !!@_cookie[ node ]
end