Module: Thaum::Concerns::Focus
- Included in:
- App
- Defined in:
- lib/thaum/concerns/focus.rb
Instance Method Summary collapse
-
#focus(sigil) ⇒ Object
— Focus —.
- #focus_next ⇒ Object
- #focus_prev ⇒ Object
- #focused_sigil ⇒ Object
- #initial_focus ⇒ Object
Instance Method Details
#focus(sigil) ⇒ Object
— Focus —
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/thaum/concerns/focus.rb', line 8 def focus(sigil) return if @modal_sigil return if @focused_sigil.equal?(sigil) return if sigil && !focusable_and_mounted?(sigil) old = @focused_sigil @focused_sigil = sigil old&.on_blur sigil&.on_focus request_render end |
#focus_next ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/thaum/concerns/focus.rb', line 20 def focus_next return if @modal_sigil leaves = effective_focus_order return if leaves.empty? idx = @focused_sigil ? (leaves.index(@focused_sigil) || -1) : -1 focus(leaves[(idx + 1) % leaves.size]) end |
#focus_prev ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/thaum/concerns/focus.rb', line 30 def focus_prev return if @modal_sigil leaves = effective_focus_order return if leaves.empty? idx = @focused_sigil ? (leaves.index(@focused_sigil) || 0) : 0 focus(leaves[(idx - 1) % leaves.size]) end |
#focused_sigil ⇒ Object
40 |
# File 'lib/thaum/concerns/focus.rb', line 40 def focused_sigil = @focused_sigil |
#initial_focus ⇒ Object
42 43 44 |
# File 'lib/thaum/concerns/focus.rb', line 42 def initial_focus (@leaf_sigils || []).find(&:focusable?) end |