Documentation
¶
Overview ¶
Package tagsinput provides a tag/chip input component for entering multiple values.
Available variants:
- New() creates a basic tags input (template: "lvt:tagsinput:default:v1")
Required lvt-* attributes: lvt-on:input, lvt-on:keydown, name
Example usage:
// In your controller/state
Tags: tagsinput.New("skills",
tagsinput.WithPlaceholder("Add skills..."),
tagsinput.WithTags("go", "typescript", "python"),
)
// In your template
{{template "lvt:tagsinput:default:v1" .Tags}}
Index ¶
- func Templates() *base.TemplateSet
- type Option
- type Tag
- type TagsInput
- func (t *TagsInput) AddTag(value string) bool
- func (t *TagsInput) CanAddMore() bool
- func (t *TagsInput) Clear()
- func (t *TagsInput) Count() int
- func (t *TagsInput) FilteredSuggestions() []string
- func (t *TagsInput) HasTag(value string) bool
- func (t *TagsInput) IsEmpty() bool
- func (t *TagsInput) RemoveLast()
- func (t *TagsInput) RemoveTag(value string)
- func (t *TagsInput) RemoveTagAt(index int)
- func (t *TagsInput) SetInput(value string)
- func (t *TagsInput) Styles() styles.TagsInputStyles
- func (t *TagsInput) Values() []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Templates ¶
func Templates() *base.TemplateSet
Templates returns the tagsinput component's template set for registration with the LiveTemplate framework.
Example usage in main.go:
import "github.com/livetemplate/lvt/components/tagsinput"
tmpl, err := livetemplate.New("app",
livetemplate.WithComponentTemplates(tagsinput.Templates()),
)
Available templates:
- "lvt:tagsinput:default:v1" - Standard tags input
Types ¶
type Option ¶
type Option func(*TagsInput)
Option is a functional option for configuring tags input.
func WithAllowDuplicates ¶
WithAllowDuplicates allows duplicate tag values.
func WithMaxTags ¶
WithMaxTags limits the number of tags (0 = unlimited).
func WithPlaceholder ¶
WithPlaceholder sets the placeholder text.
func WithSeparators ¶
WithSeparators sets the characters that trigger tag creation.
func WithStyled ¶
WithStyled enables Tailwind CSS styling for the component.
func WithSuggestions ¶
WithSuggestions sets autocomplete suggestions.
type Tag ¶
type Tag struct {
Value string // The tag value
Label string // Display text (defaults to Value if empty)
}
Tag represents a single tag/chip.
type TagsInput ¶
type TagsInput struct {
base.Base
// Tags is the list of current tags
Tags []Tag
// Input is the current input value (before becoming a tag)
Input string
// Placeholder text shown when empty
Placeholder string
// MaxTags limits the number of tags (0 = unlimited)
MaxTags int
// AllowDuplicates allows the same tag value multiple times
AllowDuplicates bool
// Separator characters that trigger tag creation (default: comma, Enter)
Separators []string
// Suggestions for autocomplete (optional)
Suggestions []string
// ShowSuggestions controls visibility of suggestion dropdown
ShowSuggestions bool
}
TagsInput is a component for entering multiple tags. Use template "lvt:tagsinput:default:v1" to render.
func New ¶
New creates a new tags input.
Example:
tags := tagsinput.New("skills",
tagsinput.WithPlaceholder("Add skills..."),
tagsinput.WithTags("go", "python"),
tagsinput.WithMaxTags(10),
)
func (*TagsInput) CanAddMore ¶
CanAddMore returns true if more tags can be added.
func (*TagsInput) FilteredSuggestions ¶
FilteredSuggestions returns suggestions that match the current input and aren't already tags.
func (*TagsInput) RemoveLast ¶
func (t *TagsInput) RemoveLast()
RemoveLast removes the last tag (for backspace behavior).
func (*TagsInput) RemoveTagAt ¶
RemoveTagAt removes a tag by index.
func (*TagsInput) Styles ¶
func (t *TagsInput) Styles() styles.TagsInputStyles
Styles returns the resolved TagsInputStyles for this component.