mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
Vue kit: the Layer Finder's buttons are UiButtons and its glyphs UiIcons
Search, Filter, the filter menu's Status and Category options and the bar's two clear chips are ghost UiButtons. Search and the options are pressed toggles in place of hand-written aria-pressed; the options take active as their pressed class, while Search keeps its own active binding, which also stays on while a query is typed. Escape in the menu still gives focus back to the Filter button, now through the UiButton's root. Every Material glyph in it is a UiIcon sized by layer-finder.css. A guard test pins it, and the migration notes say so. Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
ba89f273dc
commit
ca504fa8f6
4 files changed
+82
-19
No files matched your search
@@ -89,6 +89,15 @@ tilt-map button, whose owners still write their state into the DOM. Core's
|
|||||||
pressable chips and pills (rail card chips, map sources, cities and places)
|
pressable chips and pills (rail card chips, map sources, cities and places)
|
||||||
are `UiButton`s too; `UiChip` is a non-interactive label chip, used by
|
are `UiButton`s too; `UiChip` is a non-interactive label chip, used by
|
||||||
the voice card.
|
the voice card.
|
||||||
|
The Layer Finder's buttons (Search, Filter, the filter menu's Status and
|
||||||
|
Category options and the bar's two clear chips) are ghost `UiButton`s.
|
||||||
|
Search and the options are pressed toggles; the options' pressed class is
|
||||||
|
`active`, while Search keeps its own `active` binding, which also stays on
|
||||||
|
while a query is typed. The Filter button opens a disclosure and carries
|
||||||
|
`aria-expanded`, not `aria-pressed`. Every glyph its own template draws is
|
||||||
|
a `UiIcon` with `:size="null"`, so `layer-finder.css` still sizes them
|
||||||
|
(`src/ui/kit/layerFinderControls.test.mjs` pins it); the search field's
|
||||||
|
magnifier is `UiSearchField`'s own span.
|
||||||
`UiSelect` renders the bare native select (Core's labels sit outside it or
|
`UiSelect` renders the bare native select (Core's labels sit outside it or
|
||||||
come as an `aria-label`) with `v-model`, `options` and `disabled`;
|
come as an `aria-label`) with `v-model`, `options` and `disabled`;
|
||||||
options that carry their own attributes come through the slot, a caller's
|
options that carry their own attributes come through the slot, a caller's
|
||||||
|
|||||||
@@ -1343,6 +1343,7 @@
|
|||||||
"src/ui/kit/UiDialog.vue",
|
"src/ui/kit/UiDialog.vue",
|
||||||
"src/ui/kit/UiDialog.test.mjs",
|
"src/ui/kit/UiDialog.test.mjs",
|
||||||
"src/ui/kit/dialogs.test.mjs",
|
"src/ui/kit/dialogs.test.mjs",
|
||||||
|
"src/ui/kit/layerFinderControls.test.mjs",
|
||||||
"src/ui/styles/chip.css",
|
"src/ui/styles/chip.css",
|
||||||
"src/ui/styles/empty-state.css",
|
"src/ui/styles/empty-state.css",
|
||||||
"src/ui/rail/RailChips.vue",
|
"src/ui/rail/RailChips.vue",
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
// The Layer Finder's buttons and Material glyphs are the kit's: its template
|
||||||
|
// hand-writes no <button>, aria-pressed, Material Symbols span or inline SVG.
|
||||||
|
// Its search field is a UiSearchField.
|
||||||
|
import { test } from 'node:test';
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { readFileSync } from 'node:fs';
|
||||||
|
|
||||||
|
/** A view's template block: everything outside script and style. */
|
||||||
|
function template(file) {
|
||||||
|
const source = readFileSync(
|
||||||
|
new URL(`../views/panels/${file}`, import.meta.url),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
|
return source.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/g, '');
|
||||||
|
}
|
||||||
|
const finder = template('LayerFinder.vue');
|
||||||
|
|
||||||
|
test('the Layer Finder hand-writes no button; each is a UiButton', () => {
|
||||||
|
assert.deepEqual(finder.match(/<button\b/gi) ?? [], []);
|
||||||
|
// Search, Filter, the Status and Category options, and the two chips.
|
||||||
|
assert.equal(finder.match(/<UiButton\b/g)?.length, 6);
|
||||||
|
assert.equal(finder.match(/<UiSearchField\b/g)?.length, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('its pressed toggles leave aria-pressed to UiButton', () => {
|
||||||
|
assert.deepEqual(finder.match(/aria-pressed/g) ?? [], []);
|
||||||
|
const pressed = finder.match(/<UiButton\b[^>]*:pressed=[^>]*>/g) ?? [];
|
||||||
|
// Search and the Status and Category options.
|
||||||
|
assert.equal(pressed.length, 3);
|
||||||
|
// Only the options' active class follows their pressed state; Search's
|
||||||
|
// also stays on while a query is typed, so it keeps its own binding.
|
||||||
|
assert.equal(
|
||||||
|
pressed.filter((tag) => tag.includes('pressed-class="active"')).length,
|
||||||
|
2,
|
||||||
|
);
|
||||||
|
assert.match(
|
||||||
|
finder,
|
||||||
|
/id="layer-finder-search-btn"[^>]*:class="\{ active: searching \|\| query \}"/,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the Layer Finder hand-writes no Material glyph; each is a UiIcon', () => {
|
||||||
|
assert.deepEqual(finder.match(/material-symbols-outlined/g) ?? [], []);
|
||||||
|
assert.deepEqual(finder.match(/<svg\b/gi) ?? [], []);
|
||||||
|
const icons = finder.match(/<UiIcon\b[^>]*>/g) ?? [];
|
||||||
|
// Search, Filter, the two option radios and the two chips' close.
|
||||||
|
assert.equal(icons.length, 6);
|
||||||
|
// Without it the kit writes an 18px size that beats layer-finder.css.
|
||||||
|
for (const icon of icons) assert.match(icon, /:size="null"/);
|
||||||
|
});
|
||||||
@@ -22,6 +22,8 @@ const finder = {
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { nextTick, onBeforeUnmount, onMounted, ref, watch, computed } from 'vue';
|
import { nextTick, onBeforeUnmount, onMounted, ref, watch, computed } from 'vue';
|
||||||
import { msg, t } from '../../../i18n/index.js';
|
import { msg, t } from '../../../i18n/index.js';
|
||||||
|
import UiButton from '../../kit/UiButton.vue';
|
||||||
|
import UiIcon from '../../kit/UiIcon.vue';
|
||||||
import UiSearchField from '../../kit/UiSearchField.vue';
|
import UiSearchField from '../../kit/UiSearchField.vue';
|
||||||
|
|
||||||
// Search and filter for the Data Layers list. The rows are rendered elsewhere
|
// Search and filter for the Data Layers list. The rows are rendered elsewhere
|
||||||
@@ -185,7 +187,8 @@ async function toggleFilter() {
|
|||||||
}
|
}
|
||||||
function closeFilter({ refocus = false } = {}) {
|
function closeFilter({ refocus = false } = {}) {
|
||||||
filtering.value = false;
|
filtering.value = false;
|
||||||
if (refocus) triggerEl.value?.focus();
|
// The trigger is a UiButton; its root is the button.
|
||||||
|
if (refocus) triggerEl.value?.$el?.focus();
|
||||||
}
|
}
|
||||||
function onMenuKey(event) {
|
function onMenuKey(event) {
|
||||||
if (event.key === 'Escape') {
|
if (event.key === 'Escape') {
|
||||||
@@ -223,37 +226,37 @@ if (props.part === 'buttons') {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<template v-if="part === 'buttons'">
|
<template v-if="part === 'buttons'">
|
||||||
<button id="layer-finder-search-btn" type="button" class="layer-finder__btn" :class="{ active: searching || query }" :aria-pressed="String(searching)" :aria-label="t('Search layers')" :title="t('Search layers')" @click="toggleSearch">
|
<UiButton id="layer-finder-search-btn" class="layer-finder__btn" :class="{ active: searching || query }" :pressed="Boolean(searching)" :aria-label="t('Search layers')" :title="t('Search layers')" @click="toggleSearch">
|
||||||
<span class="material-symbols-outlined" aria-hidden="true">search</span>
|
<UiIcon name="search" :size="null" />
|
||||||
</button>
|
</UiButton>
|
||||||
<span ref="filterEl" class="layer-finder__filter">
|
<span ref="filterEl" class="layer-finder__filter">
|
||||||
<button ref="triggerEl" type="button" class="layer-finder__btn" :class="{ active: show !== 'all' || category }" :aria-expanded="String(filtering)" aria-controls="layer-finder-menu" :aria-label="t('Filter layers')" :title="t('Filter layers')" @click="toggleFilter">
|
<UiButton ref="triggerEl" class="layer-finder__btn" :class="{ active: show !== 'all' || category }" :aria-expanded="String(filtering)" aria-controls="layer-finder-menu" :aria-label="t('Filter layers')" :title="t('Filter layers')" @click="toggleFilter">
|
||||||
<span class="material-symbols-outlined" aria-hidden="true">filter_list</span>
|
<UiIcon name="filter_list" :size="null" />
|
||||||
</button>
|
</UiButton>
|
||||||
<span v-if="filtering" id="layer-finder-menu" ref="menuEl" class="layer-finder__menu" role="group" :aria-label="t('Filter layers')" @keydown="onMenuKey">
|
<span v-if="filtering" id="layer-finder-menu" ref="menuEl" class="layer-finder__menu" role="group" :aria-label="t('Filter layers')" @keydown="onMenuKey">
|
||||||
<span role="group" :aria-label="t('Status')">
|
<span role="group" :aria-label="t('Status')">
|
||||||
<span class="layer-finder__menu-head" aria-hidden="true">{{ t('Status') }}</span>
|
<span class="layer-finder__menu-head" aria-hidden="true">{{ t('Status') }}</span>
|
||||||
<button v-for="s in SHOWS" :key="s.id" type="button" :aria-pressed="String(show === s.id)" :class="{ active: show === s.id }" @click="show = s.id">
|
<UiButton v-for="s in SHOWS" :key="s.id" :pressed="show === s.id" pressed-class="active" @click="show = s.id">
|
||||||
<span class="material-symbols-outlined" aria-hidden="true">{{ show === s.id ? 'radio_button_checked' : 'radio_button_unchecked' }}</span>{{ t(s.label) }}
|
<UiIcon :name="show === s.id ? 'radio_button_checked' : 'radio_button_unchecked'" :size="null" />{{ t(s.label) }}
|
||||||
</button>
|
</UiButton>
|
||||||
</span>
|
</span>
|
||||||
<span v-if="categories.length" role="group" :aria-label="t('Category')">
|
<span v-if="categories.length" role="group" :aria-label="t('Category')">
|
||||||
<span class="layer-finder__menu-head" aria-hidden="true">{{ t('Category') }}</span>
|
<span class="layer-finder__menu-head" aria-hidden="true">{{ t('Category') }}</span>
|
||||||
<button v-for="c in categories" :key="c.key" type="button" :aria-pressed="String(category === c.key)" :class="{ active: category === c.key }" @click="pickCategory(c.key)">
|
<UiButton v-for="c in categories" :key="c.key" :pressed="category === c.key" pressed-class="active" @click="pickCategory(c.key)">
|
||||||
<span class="material-symbols-outlined" aria-hidden="true">{{ category === c.key ? 'radio_button_checked' : 'radio_button_unchecked' }}</span>{{ c.label }}
|
<UiIcon :name="category === c.key ? 'radio_button_checked' : 'radio_button_unchecked'" :size="null" />{{ c.label }}
|
||||||
</button>
|
</UiButton>
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
<div v-else-if="searching || narrowed" class="layer-finder__bar">
|
<div v-else-if="searching || narrowed" class="layer-finder__bar">
|
||||||
<UiSearchField v-if="searching" v-model="query" tag="label" class="layer-finder__field" input-id="layer-finder-input" :label="t('Search layers')" :placeholder="t('Search layers…')" @escape="(event) => { event.preventDefault(); closeSearch(); }" />
|
<UiSearchField v-if="searching" v-model="query" tag="label" class="layer-finder__field" input-id="layer-finder-input" :label="t('Search layers')" :placeholder="t('Search layers…')" @escape="(event) => { event.preventDefault(); closeSearch(); }" />
|
||||||
<button v-if="show !== 'all'" type="button" class="layer-finder__chip" @click="show = 'all'">
|
<UiButton v-if="show !== 'all'" class="layer-finder__chip" @click="show = 'all'">
|
||||||
{{ show === 'on' ? t('On') : t('Off') }}<span class="material-symbols-outlined" aria-hidden="true">close</span>
|
{{ show === 'on' ? t('On') : t('Off') }}<UiIcon name="close" :size="null" />
|
||||||
</button>
|
</UiButton>
|
||||||
<button v-if="category" type="button" class="layer-finder__chip" @click="category = ''">
|
<UiButton v-if="category" class="layer-finder__chip" @click="category = ''">
|
||||||
{{ categoryLabel }}<span class="material-symbols-outlined" aria-hidden="true">close</span>
|
{{ categoryLabel }}<UiIcon name="close" :size="null" />
|
||||||
</button>
|
</UiButton>
|
||||||
<p v-if="narrowed && shown === 0" class="layer-finder__empty" role="status">{{ t('No layers match') }}</p>
|
<p v-if="narrowed && shown === 0" class="layer-finder__empty" role="status">{{ t('No layers match') }}</p>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
Reference in new issue
Block a user