Sha256: 249dcaa0f409b699c16e49df67a8ab1a4d547cc8e2a614d8e770300e0e4dbe22
Contents?: true
Size: 846 Bytes
Versions: 35
Compression:
Stored size: 846 Bytes
Contents
import { Controller } from "@hotwired/stimulus" export default class extends Controller { static targets = [ "item" ] static values = { index: Number } connect() { this.#updateTabstops() } reset() { this.indexValue = 0 this.#updateTabstops() } prev() { if (this.indexValue > 0) { this.indexValue-- this.#updateTabstops() this.#focusCurrentItem() } } next() { if (this.indexValue < this.#lastIndex) { this.indexValue++ this.#updateTabstops() this.#focusCurrentItem() } } #updateTabstops() { this.itemTargets.forEach((element, index) => { element.tabIndex = index === this.indexValue ? 0 : -1 }) } #focusCurrentItem() { this.itemTargets[this.indexValue].focus() } get #lastIndex() { return this.itemTargets.length -1 } }
Version data entries
35 entries across 35 versions & 1 rubygems