Skip to content

Commit

Permalink
Fix focus for tabs and menu
Browse files Browse the repository at this point in the history
  • Loading branch information
lazaronixon committed Oct 15, 2024
1 parent bde0c4d commit 4d8d3e7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- Adjust checkbox and radio size
- Fix tab hover on dark mode
- Fix menu and command hover on dark mode
- Adjust menu component
- Fix focus for tabs and menu
- Set input--actor icon color

## [0.0.46] - 2024-10-14
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ export default class extends Controller {

indexValueChanged() {
this.#removeTabstops()
this.#focusCurrentItem()
}

prev() {
this.indexValue > 0 && this.indexValue--
const hasPrevious = this.indexValue > 0
hasPrevious && this.indexValue--
hasPrevious && this.#focusCurrentItem()
}

next() {
this.indexValue < this.#lastIndex && this.indexValue++
const hasNext = this.indexValue < this.#lastIndex
hasNext && this.indexValue++
hasNext && this.#focusCurrentItem()
}

reset() {
this.indexValue = 0
this.#focusCurrentItem()
}

#removeTabstops() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ export default class extends Controller {
static targets = [ "button", "tab" ]
static values = { index: Number }

indexValueChanged(index, previousIndex) {
indexValueChanged() {
this.#showCurrentTab()
this.#focusCurrentButton(previousIndex !== undefined)
}

select({ target }) {
this.indexValue = this.buttonTargets.indexOf(target)
}

prev() {
this.indexValue > 0 && this.indexValue--
const hasPrevious = this.indexValue > 0
hasPrevious && this.indexValue--
hasPrevious && this.#focusCurrentButton()
}

next() {
this.indexValue < this.#lastIndex && this.indexValue++
const hasNext = this.indexValue < this.#lastIndex
hasNext && this.indexValue++
hasNext && this.#focusCurrentButton()
}

#showCurrentTab() {
Expand All @@ -32,8 +35,8 @@ export default class extends Controller {
})
}

#focusCurrentButton(shouldFocus) {
shouldFocus && this.buttonTargets[this.indexValue].focus()
#focusCurrentButton() {
this.buttonTargets[this.indexValue].focus()
}

get #lastIndex() {
Expand Down

0 comments on commit 4d8d3e7

Please sign in to comment.