Skip to content

IconPicker

WxIconPicker is a field that holds the name of an icon and shows the icon itself. The box is the search: typing filters the set, clicking an icon chooses it.

Pick one

Model: grid

Empty, and sizes

Usage

vue
<script setup lang="ts">
import { ref } from 'vue'

const icon = ref<string | null>('grid')
</script>

<template>
  <wx-icon-picker v-model="icon" clearable />
</template>

The model is an icon name, or null when the field is empty — the same string <wx-icon> takes. Icons a site registered with registerIcons are in the panel too: the list is iconNames(), built-ins and registered ones alike.

Why not a text field

An unknown name draws nothing at all. WxIcon has no placeholder and no warning for a name the set does not have, so file-text where the set says file-txt is a label that has quietly moved to where the picture should have been — and nothing in the interface says so. This field cannot hold a name like that: what is typed is a filter, and the value only ever becomes a name that was picked out of the panel. Typing a name in full and pressing Enter picks it, since by then it is the only match left.

A name can still arrive from elsewhere — a type imported from a file, a field that was a text box last year, an icon a site registered and then stopped registering. The field marks it: the preview shows a warning glyph and says so in its tooltip, rather than the same emptiness as "no icon chosen".

Props

PropTypeDefaultDescription
modelValuestring | nullnullIcon name
clearablebooleanfalseShow a button that empties the field
placeholderstring'Search icons'Placeholder of the search box
emptyTextstring'No icon of that name'Shown when nothing matches
unknownTextstringsee belowTooltip when the held name is not in the set
clearLabelstring'Clear'Accessible name of the clear button
teleportbooleantrueRender the panel in a portal
disabledbooleanInherited from the form field when unset
size'sm' | 'md' | 'lg'Inherited from the form field when unset
status'default' | 'error'Inherited from the form field when unset
ariaLabelstringAccessible name when there is no <label>

Events

EventPayloadWhen
update:modelValuestring | nullAn icon is picked, or the field emptied
changestring | nullThe same, for forms that listen for it

Released under the MIT License.