Skip to content

Commit

Permalink
manage focus order #2991
Browse files Browse the repository at this point in the history
  • Loading branch information
hmeneuvrier committed Sep 18, 2024
1 parent 59d8e0a commit b883628
Show file tree
Hide file tree
Showing 26 changed files with 83 additions and 19 deletions.
8 changes: 7 additions & 1 deletion assets/json/Signalement/questions_profile_locataire.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
"label": "Monsieur",
"value": "mr"
}
]
],
"accessibility": {
"focus": true
}
},
{
"type": "SignalementFormTextfield",
Expand Down Expand Up @@ -124,6 +127,9 @@
"autocomplete": {
"isAbsoluteLink": false,
"route": "/bailleurs?postcode={{formStore.data.adresse_logement_adresse_detail_code_postal}}&name={{formStore.data.coordonnees_bailleur_nom_autocomplete_textfield}}&sanitize=true"
},
"accessibility": {
"focus": true
}
},
{
Expand Down
5 changes: 4 additions & 1 deletion assets/json/Signalement/questions_profile_tous.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@
"label": "En savoir plus",
"slug": "signalement_concerne_savoir_plus",
"customCss": "fr-btn--sm fr-badge fr-badge--info",
"ariaControls": "signalement_concerne_modal"
"ariaControls": "signalement_concerne_modal",
"accessibility": {
"focus": true
}
},
{
"type": "SignalementFormOnlyChoice",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export default defineComponent({
components: Object,
handleClickComponent: Function,
access_name: { type: String, default: undefined },
access_autocomplete: { type: String, default: undefined }
access_autocomplete: { type: String, default: undefined },
access_focus: { type: Boolean, default: false }
},
data () {
const updatedSubscreenData = subscreenManager.generateSubscreenData(this.id, subscreenData.body, this.validate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default defineComponent({
disabled: { type: Boolean, default: false },
access_name: { type: String, default: '' },
access_autocomplete: { type: String, default: '' },
access_focus: { type: Boolean, default: false },
// les propriétés suivantes ne sont pas utilisées,
// mais si on ne les met pas, elles apparaissent dans le DOM
// et ça soulève des erreurs W3C
Expand All @@ -72,6 +73,16 @@ export default defineComponent({
selectedSuggestionIndex: -1
}
},
mounted () {
if (this.access_focus) {
this.$nextTick(() => {
const element = document.querySelector('#' + this.idAutocomplete + '_input') as HTMLElement
if (element) {
element.focus()
}
})
}
},
created () {
document.addEventListener('click', this.closeAutocomplete)
watch(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div class="signalement-form-button" :id="id">
<button
id="button"
:type="type"
:class="[ 'fr-btn', customCss, formStore.lastButtonClicked === id ? 'fr-btn--loading fr-btn--icon-right fr-icon-refresh-line' : '' ]"
:disabled="formStore.lastButtonClicked !== ''"
Expand Down Expand Up @@ -38,6 +39,7 @@ export default defineComponent({
customCss: { type: String, default: '' },
ariaControls: { type: String, default: undefined },
clickEvent: Function,
access_focus: { type: Boolean, default: false },
// les propriétés suivantes ne sont pas utilisées,
// mais si on ne les met pas, elles apparaissent dans le DOM
// et ça soulève des erreurs W3C
Expand All @@ -51,6 +53,16 @@ export default defineComponent({
formStore
}
},
mounted () {
if (this.access_focus) {
this.$nextTick(() => {
const element = document.querySelector('#button') as HTMLElement
if (element) {
element.focus()
}
})
}
},
computed: {
actionType (): string {
if (this.action.includes(':')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export default defineComponent({
clickEvent: Function,
handleClickComponent: Function,
access_name: { type: String, default: '' },
access_autocomplete: { type: String, default: '' }
access_autocomplete: { type: String, default: '' },
access_focus: { type: Boolean, default: false }
},
data () {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default defineComponent({
clickEvent: Function,
handleClickComponent: Function,
access_name: { type: String, default: '' },
access_autocomplete: { type: String, default: '' }
access_autocomplete: { type: String, default: '' },
access_focus: { type: Boolean, default: false }
}
})
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export default defineComponent({
handleClickComponent: Function,
clickEvent: Function,
access_name: { type: String, default: undefined },
access_autocomplete: { type: String, default: undefined }
access_autocomplete: { type: String, default: undefined },
access_focus: { type: Boolean, default: false }
},
data () {
return {
Expand All @@ -66,7 +67,7 @@ export default defineComponent({
},
methods: {
updateValue (event: Event) {
let value = (event.target as HTMLInputElement).value
const value = (event.target as HTMLInputElement).value
this.$emit('update:modelValue', value)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export default defineComponent({
handleClickComponent: Function,
clickEvent: Function,
access_name: { type: String, default: undefined },
access_autocomplete: { type: String, default: undefined }
access_autocomplete: { type: String, default: undefined },
access_focus: { type: Boolean, default: false }
},
computed: {
internalValue: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default defineComponent({
hasError: { type: Boolean, default: false },
handleClickComponent: Function,
access_name: { type: String, default: '' },
access_autocomplete: { type: String, default: '' }
access_autocomplete: { type: String, default: '' },
access_focus: { type: Boolean, default: false }
},
data () {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ export default defineComponent({
clickEvent: Function,
handleClickComponent: Function,
access_name: { type: String, default: '' },
access_autocomplete: { type: String, default: '' }
access_autocomplete: { type: String, default: '' },
access_focus: { type: Boolean, default: false }
},
data () {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default defineComponent({
error: { type: String, default: '' },
access_name: { type: String, default: '' },
access_autocomplete: { type: String, default: '' },
access_focus: { type: Boolean, default: false },
// les propriétés suivantes ne sont pas utilisées,
// mais si on ne les met pas, elles apparaissent dans le DOM
// et ça soulève des erreurs W3C
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export default defineComponent({
clickEvent: Function,
handleClickComponent: Function,
access_name: { type: String, default: '' },
access_autocomplete: { type: String, default: '' }
access_autocomplete: { type: String, default: '' },
access_focus: { type: Boolean, default: false }
},
data () {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default defineComponent({
// et ça soulève des erreurs W3C
hasError: { type: Boolean, default: undefined },
access_name: { type: String, default: undefined },
access_autocomplete: { type: String, default: undefined }
access_autocomplete: { type: String, default: undefined },
access_focus: { type: Boolean, default: false }
},
methods: {
handleClick () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export default defineComponent({
clickEvent: Function,
hasError: { type: Boolean, default: undefined },
access_name: { type: String, default: undefined },
access_autocomplete: { type: String, default: undefined }
access_autocomplete: { type: String, default: undefined },
access_focus: { type: Boolean, default: false }
},
methods: {
closeModal () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default defineComponent({
validate: { type: Object, default: null },
hasError: { type: Boolean, default: false },
error: { type: String, default: '' },
access_focus: { type: Boolean, default: false },
// les propriétés suivantes ne sont pas utilisées,
// mais si on ne les met pas, elles apparaissent dans le DOM
// et ça soulève des erreurs W3C
Expand All @@ -55,6 +56,16 @@ export default defineComponent({
variablesReplacer
}
},
mounted () {
if (this.access_focus) {
this.$nextTick(() => {
const element = document.querySelector('#' + this.id + '_' + this.values[0].value) as HTMLElement
if (element) {
element.focus()
}
})
}
},
methods: {
updateValue (event: Event) {
const value = (event.target as HTMLInputElement).getAttribute('value')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ export default defineComponent({
hasError: { type: Boolean, default: false },
handleClickComponent: Function,
access_name: { type: String, default: '' },
access_autocomplete: { type: String, default: '' }
access_autocomplete: { type: String, default: '' },
access_focus: { type: Boolean, default: false }
},
data () {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export default defineComponent({
error: { type: String, default: '' },
access_name: { type: String, default: '' },
access_autocomplete: { type: String, default: '' },
access_focus: { type: Boolean, default: false },
clickEvent: Function,
// les propriétés suivantes ne sont pas utilisées,
// mais si on ne les met pas, elles apparaissent dans le DOM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export default defineComponent({
// et ça soulève des erreurs W3C
handleClickComponent: Function,
access_name: { type: String, default: '' },
access_autocomplete: { type: String, default: '' }
access_autocomplete: { type: String, default: '' },
access_focus: { type: Boolean, default: false }
},
data () {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
:handleClickComponent="handleClickComponent"
:access_name="component.accessibility?.name ?? component.slug"
:access_autocomplete="component.accessibility?.autocomplete ?? 'off'"
:access_focus="component.accessibility?.focus ?? false"
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default defineComponent({
hasError: { type: Boolean, default: undefined },
access_name: { type: String, default: undefined },
access_autocomplete: { type: String, default: undefined },
access_focus: { type: Boolean, default: false },
clickEvent: Function
},
data () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export default defineComponent({
clickEvent: Function,
handleClickComponent: Function,
access_name: { type: String, default: '' },
access_autocomplete: { type: String, default: '' }
access_autocomplete: { type: String, default: '' },
access_focus: { type: Boolean, default: false }
},
computed: {
internalValue: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default defineComponent({
tagWhenEdit: { type: String, default: '' },
access_name: { type: String, default: '' },
access_autocomplete: { type: String, default: '' },
access_focus: { type: Boolean, default: false },
// les propriétés suivantes ne sont pas utilisées,
// mais si on ne les met pas, elles apparaissent dans le DOM
// et ça soulève des erreurs W3C
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export default defineComponent({
handleClickComponent: Function,
clickEvent: Function,
access_name: { type: String, default: undefined },
access_autocomplete: { type: String, default: undefined }
access_autocomplete: { type: String, default: undefined },
access_focus: { type: Boolean, default: false }
},
data () {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export default defineComponent({
handleClickComponent: Function,
clickEvent: Function,
access_name: { type: String, default: undefined },
access_autocomplete: { type: String, default: undefined }
access_autocomplete: { type: String, default: undefined },
access_focus: { type: Boolean, default: false }
},
data () {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export default defineComponent({
handleClickComponent: Function,
clickEvent: Function,
access_name: { type: String, default: undefined },
access_autocomplete: { type: String, default: undefined }
access_autocomplete: { type: String, default: undefined },
access_focus: { type: Boolean, default: false }
},
data () {
return {
Expand Down

0 comments on commit b883628

Please sign in to comment.