Skip to content

Commit

Permalink
fix(NcRichContenteditable): provide focus-visible class
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii K. Shartsev <[email protected]>
  • Loading branch information
ShGKme committed Feb 5, 2024
1 parent c51b761 commit 8ac2eba
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/components/NcRichContenteditable/NcRichContenteditable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -913,13 +913,16 @@ export default {
// Reset active item
this.autocompleteActiveId = undefined
this.setTributeFocusVisible(false)
}
},
onTributeArrowKeyDown() {
if (!this.isAutocompleteOpen) {
return
}
this.setTributeFocusVisible(true)
this.onTributeSelectedItemWillChange()
},
Expand Down Expand Up @@ -960,10 +963,26 @@ export default {
// Handle selecting new item on mouse selection
tributeContainer.addEventListener('mousemove', () => {
this.setTributeFocusVisible(false)
this.onTributeSelectedItemWillChange()
}, { passive: true })
},
/**
* Set tribute-container--focus-visible class on the Tribute container when the user navigates the listbox via keyboard.
*
* Because the real focus is kept on the textbox, we cannot use the :focus-visible pseudo-class
* to style selected options in the autocomplete listbox.
*
* @param {boolean} withFocusVisible - should the focus-visible class be added
*/
setTributeFocusVisible(withFocusVisible) {
if (withFocusVisible) {
this.getTributeContainer().classList.add('tribute-container--focus-visible')
} else {
this.getTributeContainer().classList.remove('tribute-container--focus-visible')
}
},
},
}
</script>
Expand Down

0 comments on commit 8ac2eba

Please sign in to comment.