mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
Vue kit: UiSearchField for the Context and Layer Finder searches
UiSearchField is the search glyph, a search input with v-model and, with clearLabel, a UiCloseButton shown while text is typed that clears and refocuses. tag is div or label; attributes go to the frame, and inputId, inputClass, autocomplete and spellcheck to the input. Escape stops at the input and is emitted with its event; focus() focuses the input. search-field.css holds the declarations both skins had in common (the frame's flex row, the input's min-width, border and background), moved out of context-dock.css and layer-finder.css and loaded before them. The browser's cancel button stays each skin's own. Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
1711b4b456
commit
52dd576769
12 files changed
+303
-23
No files matched your search
@@ -0,0 +1,81 @@
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import UiCloseButton from './UiCloseButton.vue';
|
||||
|
||||
// Core's search field: the Material `search` glyph, then an
|
||||
// `<input type="search">` bound with v-model, and, when `clearLabel` is set,
|
||||
// a UiCloseButton (the `close` symbol, its label as its tip) shown while
|
||||
// text is typed, which empties the field and focuses the input again. `tag`
|
||||
// is the frame: a `div` (give it role="search") or a `label`, which names
|
||||
// the input by wrapping it. Attributes and classes pass through to the frame,
|
||||
// so each site keeps its feature class; the input takes `inputId`,
|
||||
// `inputClass`, `autocomplete` and `spellcheck`, and the clear button
|
||||
// `clearClass`. Escape, pressed in the input, stops there and is emitted
|
||||
// with its event, so a caller that also prevents the browser's own Escape
|
||||
// does so. `focus()` focuses the input. The kit classes `ui-search-field`
|
||||
// and `ui-search-field__input` (search-field.css) are the frame's flex row
|
||||
// and the bare input; the browser's own cancel button is left as it is.
|
||||
const props = defineProps({
|
||||
modelValue: { type: String, default: '' },
|
||||
/** The input's accessible name (aria-label). */
|
||||
label: { type: String, required: true },
|
||||
placeholder: { type: String, default: undefined },
|
||||
tag: {
|
||||
type: String,
|
||||
default: 'div',
|
||||
validator: (value) => ['div', 'label'].includes(value),
|
||||
},
|
||||
inputId: { type: String, default: undefined },
|
||||
inputClass: { type: String, default: undefined },
|
||||
autocomplete: { type: String, default: undefined },
|
||||
spellcheck: { type: String, default: undefined },
|
||||
/** The clear button's accessible name and tip; none without it. */
|
||||
clearLabel: { type: String, default: undefined },
|
||||
clearClass: { type: String, default: undefined },
|
||||
});
|
||||
const emit = defineEmits(['update:modelValue', 'escape']);
|
||||
const input = ref(null);
|
||||
// The input keeps Vue's native v-model, as both fields had.
|
||||
const text = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => emit('update:modelValue', value),
|
||||
});
|
||||
|
||||
function focus() {
|
||||
input.value?.focus();
|
||||
}
|
||||
|
||||
function clear() {
|
||||
emit('update:modelValue', '');
|
||||
focus();
|
||||
}
|
||||
|
||||
defineExpose({ focus });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<component :is="props.tag" class="ui-search-field">
|
||||
<span class="material-symbols-outlined" aria-hidden="true">search</span>
|
||||
<input
|
||||
:id="props.inputId"
|
||||
ref="input"
|
||||
v-model="text"
|
||||
type="search"
|
||||
class="ui-search-field__input"
|
||||
:class="props.inputClass"
|
||||
:placeholder="props.placeholder"
|
||||
:aria-label="props.label"
|
||||
:autocomplete="props.autocomplete"
|
||||
:spellcheck="props.spellcheck"
|
||||
@keydown.esc.stop="emit('escape', $event)"
|
||||
/>
|
||||
<UiCloseButton
|
||||
v-if="props.clearLabel && props.modelValue"
|
||||
:class="props.clearClass"
|
||||
glyph="icon"
|
||||
:label="props.clearLabel"
|
||||
:title="props.clearLabel"
|
||||
@click="clear"
|
||||
/>
|
||||
</component>
|
||||
</template>
|
||||
Reference in new issue
Block a user