tagsinput

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 3 Imported by: 0

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

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

func WithAllowDuplicates(allow bool) Option

WithAllowDuplicates allows duplicate tag values.

func WithMaxTags

func WithMaxTags(max int) Option

WithMaxTags limits the number of tags (0 = unlimited).

func WithPlaceholder

func WithPlaceholder(placeholder string) Option

WithPlaceholder sets the placeholder text.

func WithSeparators

func WithSeparators(seps ...string) Option

WithSeparators sets the characters that trigger tag creation.

func WithStyled

func WithStyled(styled bool) Option

WithStyled enables Tailwind CSS styling for the component.

func WithSuggestions

func WithSuggestions(suggestions ...string) Option

WithSuggestions sets autocomplete suggestions.

func WithTags

func WithTags(values ...string) Option

WithTags sets initial tags from string values.

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

func New(id string, opts ...Option) *TagsInput

New creates a new tags input.

Example:

tags := tagsinput.New("skills",
    tagsinput.WithPlaceholder("Add skills..."),
    tagsinput.WithTags("go", "python"),
    tagsinput.WithMaxTags(10),
)

func (*TagsInput) AddTag

func (t *TagsInput) AddTag(value string) bool

AddTag adds a new tag if valid.

func (*TagsInput) CanAddMore

func (t *TagsInput) CanAddMore() bool

CanAddMore returns true if more tags can be added.

func (*TagsInput) Clear

func (t *TagsInput) Clear()

Clear removes all tags.

func (*TagsInput) Count

func (t *TagsInput) Count() int

Count returns the number of tags.

func (*TagsInput) FilteredSuggestions

func (t *TagsInput) FilteredSuggestions() []string

FilteredSuggestions returns suggestions that match the current input and aren't already tags.

func (*TagsInput) HasTag

func (t *TagsInput) HasTag(value string) bool

HasTag checks if a tag value already exists.

func (*TagsInput) IsEmpty

func (t *TagsInput) IsEmpty() bool

IsEmpty returns true if there are no tags.

func (*TagsInput) RemoveLast

func (t *TagsInput) RemoveLast()

RemoveLast removes the last tag (for backspace behavior).

func (*TagsInput) RemoveTag

func (t *TagsInput) RemoveTag(value string)

RemoveTag removes a tag by value.

func (*TagsInput) RemoveTagAt

func (t *TagsInput) RemoveTagAt(index int)

RemoveTagAt removes a tag by index.

func (*TagsInput) SetInput

func (t *TagsInput) SetInput(value string)

SetInput updates the current input value.

func (*TagsInput) Styles

func (t *TagsInput) Styles() styles.TagsInputStyles

Styles returns the resolved TagsInputStyles for this component.

func (*TagsInput) Values

func (t *TagsInput) Values() []string

Values returns all tag values as a slice.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL