-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add focus state styling for tabbable fields via Plugin
- Loading branch information
Showing
12 changed files
with
113 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.v-btn:after { | ||
content: none; | ||
} | ||
|
||
a:focus-visible, | ||
.v-radio.v-selection-control--focus-visible, | ||
.v-btn:focus-visible, | ||
.tab-focused .v-field { | ||
outline: 2px solid $focus-outline; | ||
outline-offset: 2px; | ||
} | ||
|
||
.v-checkbox-btn.v-selection-control--focus-visible .v-selection-control__wrapper { | ||
outline: 2px solid $focus-outline; | ||
border-radius: 50%; | ||
} | ||
|
||
.v-icon:focus-visible { | ||
outline-color: $focus-outline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
@import 'theme.scss'; | ||
@import 'accessibility.scss'; | ||
|
||
@font-face { | ||
font-family: 'BCSans'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
class="mt-n1" | ||
color="primary" | ||
v-bind="props" | ||
tabindex="0" | ||
> | ||
mdi-information-outline | ||
</v-icon> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ | |
color="primary" | ||
v-bind="props" | ||
class="mt-n1" | ||
tabindex="0" | ||
> | ||
mdi-information-outline | ||
</v-icon> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
color="primary" | ||
v-bind="props" | ||
class="mr-1" | ||
tabindex="0" | ||
> | ||
mdi-information-outline | ||
</v-icon> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Plugin to modify the VTextField component to add a 'tab-focused' css class when the input | ||
* is focused via the Tab key. This allows to style the v-text-field's input differently | ||
* when it's focused with the keyboard, compared to when it's clicked with the mouse. | ||
* | ||
* The event listeners are cleaned up when the component is unmounted. | ||
*/ | ||
export default { | ||
install(app) { | ||
const TAB_KEY = 'Tab' | ||
|
||
// Access the VTextField component if it's globally registered | ||
const VTextField = app.component('VTextField') | ||
|
||
if (!VTextField) return | ||
|
||
// Store the original mount function | ||
const originalMount = VTextField.mounted | ||
|
||
// Modify the mounted lifecycle hook | ||
VTextField.mounted = function () { | ||
// Call any existing mounted functions | ||
if (originalMount) originalMount.call(this) | ||
|
||
const input = this.$el.querySelector('input') | ||
if (!input) return | ||
|
||
const handleKeyDown = event => { | ||
if (event.key === TAB_KEY) { | ||
input.lastKeyPressed = TAB_KEY | ||
} | ||
} | ||
|
||
const handleFocus = () => { | ||
if (input.lastKeyPressed === TAB_KEY) { | ||
this.$el.classList.add('tab-focused') | ||
} | ||
input.lastKeyPressed = '' // Reset after check | ||
} | ||
|
||
const handleBlur = () => { | ||
this.$el.classList.remove('tab-focused') | ||
} | ||
|
||
window.addEventListener('keydown', handleKeyDown) | ||
input.addEventListener('focus', handleFocus) | ||
input.addEventListener('blur', handleBlur) | ||
|
||
input.cleanupEventListeners = () => { | ||
window.removeEventListener('keydown', handleKeyDown) | ||
input.removeEventListener('focus', handleFocus) | ||
input.removeEventListener('blur', handleBlur) | ||
} | ||
} | ||
|
||
// Modify the unmounted lifecycle hook to remove all event listeners | ||
VTextField.unmounted = function () { | ||
const input = this.$el.querySelector('input') | ||
if (input && input.cleanupEventListeners) { | ||
input.cleanupEventListeners() | ||
} | ||
} | ||
} | ||
} |