A pack of extensions for grommet 2
created:7/7/2021
updated:7/7/2021
loc
181
comments
3%
passed
10
failed
10
coverage
20%

Tags

avatar of atanasster

A list of tags that can be removed.

Component

import { Tags } from 'grommet-controls';

Main

() => <TagsInput />

Properties

Name
Description
Default
ITagsProps(8 properties)
children

Function that will be called when each option is rendered

((tags: TagValueType[], index: number, value: TagValueType) => ReactNode) & ReactNode
-
focusable

Whether the tag list is focusable

boolean
true
icon

Icon element to remove a tag

ReactNode
<FormClose />
tagProps
Tag elements
<Box />
and
<Text />
properties
ITagOwnProps & BoxProps & Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "onChange">
-
onChange

Function that will be called when the user removes a tag

(event: { option: TagValueType[]; value: TagValueType; target: Element | Text; }) => void
-
onClick

Function that will be called when the user clicks on a tag

((event: MouseEvent<HTMLDivElement, MouseEvent>, value: TagValueType) => void) & ((...args: any[]) => any)
-
placeholder

Placeholder text to use when no value is provided

string
-
value

List of tag items to display

TagValueType
[]
BoxProps(27 properties)

Commits

Date
Author
Commit Message
8/31/2020

atanasster

avatar of atanasster
update stories titles and navigation
8/27/2019

atanasster

avatar of atanasster
initial commit 2.x alpha
2 commits

External dependencies

package
imports
peer
grommet
^2.15.0
TextKeyboardBoxPropsBox
*
FormClose
*
react
^17.0.1
ReactRefObjectComponent
*
react-dom
^17.0.1
findDOMNode
*

Internal dependencies

file
imports
"../Tag"
"./TagsProps"
ITagsProps

Component JSX

<Tags
focusableplaceholdervalueonChangetagProps
/>
<Text
colorstyle
/>
grommet
^2.15.0
<Keyboard
onEnteronSpaceonLeftonRight
>
grommet
^2.15.0
<Box
tabIndexrefdirectionoverflowstyle
>
grommet
^2.15.0
<Tag
keyariaCheckeda11yTitlelabelrefonClickonChangeicon
/>
Tag
from"../Tag"

Stories

A 11 Y Title

() => <TagsInput a11yTitle="Grommet tags" />

Children

() => {
const [tags, setTags] = React.useState(defaultTags);
const onChangeTags = ({ option }) => setTags(option);
const removeTag = tagIndex =>
setTags(tags.filter((_, index) => index !== tagIndex));
return (
<Tags value={tags} focusable={false} onChange={onChangeTags}>
{(tag, index) => (
<Box
key={`remove_${index}`}
pad={{
horizontal: 'xsmall',
}}
>
<Button
label={tag}
icon={<Trash />}
onClick={() => removeTag(index)}
/>
</Box>
)}
</Tags>
);
}

Icon

() => <TagsInput icon={<FormSubtract />} />

Direction

() => <TagsInput direction="column" />

Tag Props

() => (
<TagsInput
tagProps={{
background: 'status-critical',
size: 'large',
border: {
color: 'brand',
size: 'medium',
},
}}
/>
)

On Click

() => (
<TagsInput onClick={() => console.log('onClick')} />
)

Focusable

() => <TagsInput focusable={false} />

Placeholder

() => (
<TagsInput placeholder="No selection" />
)

Value

() => <TagsInput value="tag" />