|
59 | 59 | this.selected = this.defaultValue; |
60 | 60 | this.selectedLabel = label; |
61 | 61 | this.$dispatch('field-change', { name: '{{ name }}', value: this.defaultValue, label }); |
| 62 | + }, |
| 63 | + focusNextEnabled(el) { |
| 64 | + let n = el.nextElementSibling; |
| 65 | + while (n && n.hasAttribute('data-value') && this.disabledValues.includes(n.dataset.value)) { |
| 66 | + n = n.nextElementSibling; |
| 67 | + } |
| 68 | + if (n && n.hasAttribute('data-value')) n.focus(); |
| 69 | + }, |
| 70 | + focusPrevEnabled(el) { |
| 71 | + let p = el.previousElementSibling; |
| 72 | + while (p && p.hasAttribute('data-value') && this.disabledValues.includes(p.dataset.value)) { |
| 73 | + p = p.previousElementSibling; |
| 74 | + } |
| 75 | + if (p && p.hasAttribute('data-value')) p.focus(); |
| 76 | + else this.$refs.trigger.focus(); |
| 77 | + }, |
| 78 | + firstEnabledOption() { |
| 79 | + const opts = this.$refs.list.querySelectorAll('[data-value]'); |
| 80 | + for (const el of opts) { |
| 81 | + if (!this.disabledValues.includes(el.dataset.value)) return el; |
| 82 | + } |
| 83 | + return null; |
62 | 84 | } |
63 | 85 | }"> |
64 | 86 | {# djlint:on #} |
|
85 | 107 | @keydown.enter.prevent="open = !open" |
86 | 108 | @keydown.space.prevent="open = !open" |
87 | 109 | @keydown.escape.prevent="open = false" |
88 | | - @keydown.arrow-down.prevent="open = true; $nextTick(() => $refs.list.querySelector('[role=option]')?.focus())" |
| 110 | + @keydown.arrow-down.prevent="open = true; $nextTick(() => firstEnabledOption()?.focus())" |
89 | 111 | :aria-expanded="open" |
90 | 112 | aria-haspopup="listbox" |
91 | 113 | {% if label %}aria-labelledby="field-{{ name }}-label"{% endif %} |
|
131 | 153 | :aria-disabled="disabledValues.includes('{{ value }}')" |
132 | 154 | data-value="{{ value }}" |
133 | 155 | data-label="{{ label }}" |
134 | | - @click="choose('{{ value }}', '{{ label }}')" |
135 | | - @keydown.enter.prevent="choose('{{ value }}', '{{ label }}')" |
136 | | - @keydown.space.prevent="choose('{{ value }}', '{{ label }}')" |
137 | | - @keydown.arrow-down.prevent="$el.nextElementSibling?.focus()" |
138 | | - @keydown.arrow-up.prevent="$el.previousElementSibling?.hasAttribute('data-value') ? $el.previousElementSibling.focus() : $refs.trigger.focus()" |
139 | | - tabindex="0">{{ label }}</div> |
| 156 | + @click="if (!disabledValues.includes('{{ value }}')) choose('{{ value }}', '{{ label }}')" |
| 157 | + @keydown.enter.prevent="if (!disabledValues.includes('{{ value }}')) choose('{{ value }}', '{{ label }}')" |
| 158 | + @keydown.space.prevent="if (!disabledValues.includes('{{ value }}')) choose('{{ value }}', '{{ label }}')" |
| 159 | + @keydown.arrow-down.prevent="focusNextEnabled($el)" |
| 160 | + @keydown.arrow-up.prevent="focusPrevEnabled($el)" |
| 161 | + :tabindex="disabledValues.includes('{{ value }}') ? -1 : 0">{{ label }}</div> |
140 | 162 | {% endfor %} |
141 | 163 | </div> |
142 | 164 | </div> |
|
0 commit comments