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:
Sameh KhamisandManjunath Paparaju committed 2026-11-19 03:21:08 -08:00
1 parent ba89f273dc
commit ca504fa8f6
4 files changed
+82 -19

No files matched your search

+50
View File
@@ -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 -19
View File
@@ -22,6 +22,8 @@ const finder = {
<script setup>
import { nextTick, onBeforeUnmount, onMounted, ref, watch, computed } from 'vue';
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';
// Search and filter for the Data Layers list. The rows are rendered elsewhere
@@ -185,7 +187,8 @@ async function toggleFilter() {
}
function closeFilter({ refocus = 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) {
if (event.key === 'Escape') {
@@ -223,37 +226,37 @@ if (props.part === 'buttons') {
<template>
<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">
<span class="material-symbols-outlined" aria-hidden="true">search</span>
</button>
<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">
<UiIcon name="search" :size="null" />
</UiButton>
<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">
<span class="material-symbols-outlined" aria-hidden="true">filter_list</span>
</button>
<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">
<UiIcon name="filter_list" :size="null" />
</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 role="group" :aria-label="t('Status')">
<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">
<span class="material-symbols-outlined" aria-hidden="true">{{ show === s.id ? 'radio_button_checked' : 'radio_button_unchecked' }}</span>{{ t(s.label) }}
</button>
<UiButton v-for="s in SHOWS" :key="s.id" :pressed="show === s.id" pressed-class="active" @click="show = s.id">
<UiIcon :name="show === s.id ? 'radio_button_checked' : 'radio_button_unchecked'" :size="null" />{{ t(s.label) }}
</UiButton>
</span>
<span v-if="categories.length" role="group" :aria-label="t('Category')">
<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)">
<span class="material-symbols-outlined" aria-hidden="true">{{ category === c.key ? 'radio_button_checked' : 'radio_button_unchecked' }}</span>{{ c.label }}
</button>
<UiButton v-for="c in categories" :key="c.key" :pressed="category === c.key" pressed-class="active" @click="pickCategory(c.key)">
<UiIcon :name="category === c.key ? 'radio_button_checked' : 'radio_button_unchecked'" :size="null" />{{ c.label }}
</UiButton>
</span>
</span>
</span>
</template>
<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(); }" />
<button v-if="show !== 'all'" type="button" class="layer-finder__chip" @click="show = 'all'">
{{ show === 'on' ? t('On') : t('Off') }}<span class="material-symbols-outlined" aria-hidden="true">close</span>
</button>
<button v-if="category" type="button" class="layer-finder__chip" @click="category = ''">
{{ categoryLabel }}<span class="material-symbols-outlined" aria-hidden="true">close</span>
</button>
<UiButton v-if="show !== 'all'" class="layer-finder__chip" @click="show = 'all'">
{{ show === 'on' ? t('On') : t('Off') }}<UiIcon name="close" :size="null" />
</UiButton>
<UiButton v-if="category" class="layer-finder__chip" @click="category = ''">
{{ categoryLabel }}<UiIcon name="close" :size="null" />
</UiButton>
<p v-if="narrowed && shown === 0" class="layer-finder__empty" role="status">{{ t('No layers match') }}</p>
</div>
</template>