Tags input
A list of tags as removable chips, added with Enter or a comma.
Previews are drawn in the theme you made.
Edit itBasic #
- effect
- foldkit
import { Bundles, Recipes, TagsInput, TagsInputSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// One hidden input per tag under `name`, so a form submits the list.
// Backspace in an empty field and the arrows move between the chips.
export default example({
title: 'Basic',
slots: TagsInputSlots,
recipe: Recipes.TagsInput,
state: Bundles.TagsInput.with({ id: 'topics', tags: ['effect', 'foldkit'] }),
view: ({ style, model, onMessage, h }) =>
TagsInput.view(
{ model, onMessage, label: 'Topics', placeholder: 'Add a topic', name: 'topics', style },
h,
),
})In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.
A maximum #
- urgent
- design
import { Bundles, Recipes, TagsInput, TagsInputSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// At most three: a fourth is refused, said under the field, and the field
// shakes once. The limit is the state's, so it is an arg and not a view option.
export default example({
title: 'A maximum',
slots: TagsInputSlots,
recipe: Recipes.TagsInput,
state: Bundles.TagsInput.with({ id: 'labels', tags: ['urgent', 'design'], max: 3 }),
view: ({ style, model, onMessage, h }) =>
TagsInput.view({ model, onMessage, label: 'Labels, up to three', style }, h),
})In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.
Refusals #
- effect
- foldkit
import { Bundles, Recipes, TagsInput, TagsInputSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// Type a tag the field holds already: the refusal is said in your words.
export default example({
title: 'Refusals',
slots: TagsInputSlots,
recipe: Recipes.TagsInput,
state: Bundles.TagsInput.with({ id: 'refusals', tags: ['effect', 'foldkit'] }),
view: ({ style, model, onMessage, h }) =>
TagsInput.view(
{
model,
onMessage,
label: 'Topics',
placeholder: 'Type effect again',
words: {
repeat: '“{tag}” is on the list already.',
empty: 'Type a topic first.',
full: 'That makes more than {max}.',
},
style,
},
h,
),
})In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.
Configure once #
- ada
- grace
import { Bundles, Recipes, TagsInput, TagsInputSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// Given once: what every tags field of the application shares. A field that
// is left with text in it adds the tag, and its remove buttons say so in
// the application's words.
const Tags = TagsInput.configure({
base: { addOnBlur: true, placeholder: 'Add and press Enter', words: { mark: '✕' } },
presets: { people: { placeholder: 'Add a person', words: { remove: 'Uninvite {tag}' } } },
})
export default example({
title: 'Configure once',
slots: TagsInputSlots,
recipe: Recipes.TagsInput,
state: Bundles.TagsInput.with({ id: 'invited', tags: ['ada', 'grace'] }),
view: ({ style, model, onMessage, h }) =>
Tags.view({ model, onMessage, label: 'Invited', preset: 'people', style }, h),
})In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.
Usage
Each example above is a module of its own, shown whole and run as shown, over the theme module Create a theme writes. The page hands it the style picked above.
Related
- Keys of your own Add the application’s keys with the routes option, beside the ones the widget handles; the widget’s
conflict(routes)judges a candidate set without drawing it. - Keeping focus when something is removed A control that leaves the page takes its focus with it: say where focus goes next, to a neighbour (
FocusRecovery), to the opener (focusReturn) or to a control (keepFocus). - What a form submits Give the widget a name and a form reads it as it reads a native field.