ServerList keyboard controls

This commit is contained in:
James Lyne 2021-05-26 03:04:37 +01:00
parent 71edab6b74
commit bbf057c84b
2 changed files with 18 additions and 4 deletions

View File

@ -18,7 +18,7 @@
<CollapsibleSection v-if="servers.size > 1" name="servers"> <CollapsibleSection v-if="servers.size > 1" name="servers">
<template v-slot:heading>{{ heading }}</template> <template v-slot:heading>{{ heading }}</template>
<template v-slot:default> <template v-slot:default>
<ul class="section__content menu" role="listbox"> <ul class="section__content menu" role="listbox" aria-labelledby="servers-heading">
<ServerListItem :server="server" v-for="[name, server] in servers" :key="name"></ServerListItem> <ServerListItem :server="server" v-for="[name, server] in servers" :key="name"></ServerListItem>
</ul> </ul>
</template> </template>

View File

@ -15,9 +15,10 @@
--> -->
<template> <template>
<li :class="{'server': true, 'server--selected': currentServer && server.id === currentServer.id}"> <li :class="{'server': true, 'server--selected': selected}" role="none">
<button type="button" :class="{'active': currentServer && server.id === currentServer.id}" <button type="button" :class="{'active': selected}"
:title="server.label || server.id" @click="setCurrentServer(server.id)">{{ server.label || server.id }} role="menuitemradio" :aria-checked="selected" :title="server.label || server.id"
@click="setCurrentServer(server.id)" @keydown="(e) => handleKeydown(e, server.id)">{{ server.label || server.id }}
</button> </button>
</li> </li>
</template> </template>
@ -40,10 +41,23 @@ export default defineComponent({
computed: { computed: {
currentServer(): LiveAtlasServerDefinition | undefined { currentServer(): LiveAtlasServerDefinition | undefined {
return useStore().state.currentServer; return useStore().state.currentServer;
},
selected(): boolean {
return this.currentServer && this.server.id === this.currentServer.id;
} }
}, },
methods: { methods: {
handleKeydown(e: KeyboardEvent, serverId: string) {
if(e.key !== ' ' && e.key !== 'Enter') {
return;
}
e.preventDefault();
this.setCurrentServer(serverId);
},
setCurrentServer(serverId: string) { setCurrentServer(serverId: string) {
useStore().commit(MutationTypes.SET_CURRENT_SERVER, serverId); useStore().commit(MutationTypes.SET_CURRENT_SERVER, serverId);
} }