Sha256: e300690a91f08e191d12d6d7a3522fd6a3708f7d00cadfada1cacf9de9e6a770
Contents?: true
Size: 782 Bytes
Versions: 1
Compression:
Stored size: 782 Bytes
Contents
import { Controller } from "@hotwired/stimulus" export default class extends Controller { static targets = [ "item" ] static values = { index: { type: Number, default: -1 } } indexValueChanged(index) { this.#removeTabstops() this.#focusCurrentItem(index !== -1) } prev() { this.indexValue > 0 && this.indexValue-- } next() { this.indexValue < this.#lastIndex && this.indexValue++ } reset() { this.indexValue = -1 } #removeTabstops() { this.itemTargets.forEach(item => item.tabIndex = -1) } #focusCurrentItem(shouldFocus) { if (shouldFocus) this.itemTargets[this.indexValue].tabIndex = 0 if (shouldFocus) this.itemTargets[this.indexValue].focus() } get #lastIndex() { return this.itemTargets.length -1 } }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
css-zero-0.0.46 | lib/generators/css_zero/add/templates/app/javascript/controllers/menu_controller.js |