-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
feat: Add VList "Strategy" Mode with Index Tracking #22328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MatthewAry
wants to merge
4
commits into
master
Choose a base branch
from
matthewary/feat-VList-navigation-modes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+92
−11
Conversation
This file contains hidden or 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
johnleider
reviewed
Nov 14, 2025
johnleider
reviewed
Nov 14, 2025
johnleider
reviewed
Nov 14, 2025
Co-authored-by: John Leider <[email protected]>
J-Sek
requested changes
Nov 15, 2025
Comment on lines
+279
to
320
| let handled = false | ||
|
|
||
| if (props.navigationStrategy === 'track') { | ||
| let nextIdx: number | null = null | ||
|
|
||
| if (e.key === 'ArrowDown') { | ||
| nextIdx = getNextIndex('next') | ||
| handled = true | ||
| } else if (e.key === 'ArrowUp') { | ||
| nextIdx = getNextIndex('prev') | ||
| handled = true | ||
| } else if (e.key === 'Home') { | ||
| nextIdx = getNextIndex('first') | ||
| handled = true | ||
| } else if (e.key === 'End') { | ||
| nextIdx = getNextIndex('last') | ||
| handled = true | ||
| } | ||
|
|
||
| if (handled && nextIdx !== null && nextIdx !== -1) { | ||
| navigationIndex.value = nextIdx | ||
| } | ||
| } else { | ||
| return | ||
| if (e.key === 'ArrowDown') { | ||
| focus('next') | ||
| handled = true | ||
| } else if (e.key === 'ArrowUp') { | ||
| focus('prev') | ||
| handled = true | ||
| } else if (e.key === 'Home') { | ||
| focus('first') | ||
| handled = true | ||
| } else if (e.key === 'End') { | ||
| focus('last') | ||
| handled = true | ||
| } | ||
| } | ||
|
|
||
| e.preventDefault() | ||
| if (handled) { | ||
| e.preventDefault() | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
| let handled = false | |
| if (props.navigationStrategy === 'track') { | |
| let nextIdx: number | null = null | |
| if (e.key === 'ArrowDown') { | |
| nextIdx = getNextIndex('next') | |
| handled = true | |
| } else if (e.key === 'ArrowUp') { | |
| nextIdx = getNextIndex('prev') | |
| handled = true | |
| } else if (e.key === 'Home') { | |
| nextIdx = getNextIndex('first') | |
| handled = true | |
| } else if (e.key === 'End') { | |
| nextIdx = getNextIndex('last') | |
| handled = true | |
| } | |
| if (handled && nextIdx !== null && nextIdx !== -1) { | |
| navigationIndex.value = nextIdx | |
| } | |
| } else { | |
| return | |
| if (e.key === 'ArrowDown') { | |
| focus('next') | |
| handled = true | |
| } else if (e.key === 'ArrowUp') { | |
| focus('prev') | |
| handled = true | |
| } else if (e.key === 'Home') { | |
| focus('first') | |
| handled = true | |
| } else if (e.key === 'End') { | |
| focus('last') | |
| handled = true | |
| } | |
| } | |
| e.preventDefault() | |
| if (handled) { | |
| e.preventDefault() | |
| } | |
| } | |
| const direction = getNavigatonDirection(e.key) | |
| if (direction !== null) { | |
| e.preventDefault() | |
| if (props.navigationStrategy === 'track') { | |
| navigationIndex.value = getNextIndex(direction) | |
| } else { | |
| focus(direction) | |
| } | |
| } | |
| } | |
| function getNavigatonDirection (key: string) { | |
| switch (key) { | |
| case 'ArrowUp': return 'prev' | |
| case 'ArrowDown': return 'next' | |
| case 'Home': return 'first' | |
| case 'End': return 'last' | |
| default: return null | |
| } | |
| } |
Contributor
|
At which point do we supplement visual feedback? I have a feeling it should be a part of this PR. watch(navigationIndex, v => {
activateSingle(v)
// ...and scroll
})// nested.ts
// naive implementation, without testing with expandable and nested lists... but maybe it is fine?
activateSingle: (index: number) => {
const targetValue = [...nodeIds].at(index)
activated.value = new Set(targetValue !== undefined ? [targetValue] : [])
},Playground (from one of my oldest demos)<template>
<v-app theme="dark">
<div class="d-flex justify-space-around">
<v-menu v-model="open" :close-on-content-click="false">
<template #activator="{ props }">
<v-btn color="primary" v-bind="props">{{ selection[0] }}</v-btn>
</template>
<v-card>
<v-text-field
ref="searchField"
v-model="search"
autocomplete="off"
class="ma-1"
density="compact"
min-width="200"
variant="outlined"
hide-details
@keydown.down="moveDown"
@keydown.enter="selectFirstVisibleItem"
@keydown.up="moveUp"
/>
<v-list
v-model:navigation-index="listNavIndex"
v-model:selected="selection"
:items="visibleItems"
class="py-0"
density="compact"
elevation="0"
max-height="300"
navigation-strategy="track"
activatable
item-props
mandatory
@update:selected="open = false"
>
<template #item="{ props }">
<v-list-item v-bind="props">
<template v-if="search" #title>
<span>{{ props.title.split(searchRegex, 1)[0] }}</span>
<span class="font-weight-bold">{{ props.title.match(searchRegex)[0] }}</span>
<span>{{
props.title.substring(props.title.split(searchRegex)[0].length
+ search.length) }}</span>
</template>
</v-list-item>
</template>
</v-list>
</v-card>
</v-menu>
</div>
</v-app>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
const selection = ref(['Apple'])
const search = ref('')
const searchField = ref()
const listNavIndex = ref<number>()
function moveUp () {
listNavIndex.value = Math.max(0, (listNavIndex.value ?? visibleItems.value.length) - 1)
}
function moveDown () {
listNavIndex.value = Math.min(visibleItems.value.length, (listNavIndex.value ?? -1) + 1)
}
const open = ref(false)
const items = [
{ title: 'Apple', value: 'Apple' },
{ title: 'Orange', value: 'Orange' },
{ title: 'Banana', value: 'Banana' },
{ title: 'Grapefruit', value: 'Grapefruit' },
].concat(
[...new Array(50)].map((_, i) => ({
title: `item #${i}`,
value: `item #${i}`,
}))
)
const searchRegex = computed(() => {
const regEscape = v => v.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
return new RegExp(regEscape(search.value), 'i')
})
const visibleItems = computed(() => {
return search.value
? items.filter(x => searchRegex.value.test(x.title))
: items
})
function selectFirstVisibleItem () {
if (!visibleItems.value.length) return
selection.value = [visibleItems.value[0].value]
open.value = false
}
watch(open, v => {
if (v) {
setTimeout(() => searchField.value.focus(), 200)
} else {
setTimeout(() => search.value = '', 300)
}
})
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://bin.vuetifyjs.com/bins/l_ScLQ
Add VList "Strategy" Mode with Index Tracking
The Problem (Context)
VList's keyboard navigation assumes: focus movement to items
VCommandPalette needs: index tracking without focus movement
Currently VCommandPalette works around this by:
tabindex=-1on items (breaks accessibility)The Solution
Add two keyboard navigation modes to VList:
Mode 1: 'focus' (default, current behavior)
focusChild()utilityMode 2: 'track' (new, for VCommandPalette)
Why This Works