ember-tags-input

0.3.0 • Public • Published

ember-tags-input

Demo

ember-tags-input is a simple Ember addon that converts a user's typing into tags. New tags are created when the user types a comma, space, semi colon or hits the enter key. Tags can be removed using the backspace key or by clicking the x button on each tag. Tags can be edited by click on existing tag.

Installation

ember install ember-tags-input

Add imports to ember-cli-build.js file for using the default styles

app.import('node_modules/ember-tags-input/vendor/styles/eti-svg-icons.css');
app.import('node_modules/ember-tags-input/vendor/styles/ember-tags-input.css');

Usage

In the simplest case, just pass a list of tags to render and actions for adding and removing tags. The component will never change the tags list for you, it will instead call actions when changes need to be made. The component will yield each tag in the list, allowing you to render it as you wish.

{{#ember-tags-input
   tagsData=tags
   onAddTag=(action addTag)
   onAddTags=(action addTags)
   onReplaceTagAtIndex=(action replaceTagAtIndex)
   onReplaceTagWithTagsAtIndex=(action replaceTagWithTagsAtIndex)
   onRemoveTagAtIndex=(action removeTagAtIndex)
   as |tagLabel|
}}
  {{tagLabel}}
{{/ember-tags-input}}
import Controller from '@ember/controller';
 
export default Controller.extend({
  tags: null,
 
  init() {
    this._super(...arguments);
 
    this.set('tags', ['tag-1', 'tag-2', 'tag-3']);
  },
 
  addTag(newTag) {
    this.get('tags').addObject(newTag);
  },
 
  addTags(newTags) {
    this.get('tags').addObject(newTags);
  },
 
  replaceTagAtIndex(tag, index) {
    this.get('tags').replace(index, 1, [tag]);
  },
 
  replaceTagWithTagsAtIndex(tags, index) {
    this.get('tags').replace(index, 1, tags);
  },
 
  removeTagAtIndex(index) {
    this.get('tags').removeAt(index);
  }
});

Options

tags

  • An array of tags to render.
  • default: null

readOnly

  • If a read only view of the tags should be displayed. If enabled, existing tags can't be edited or removed and new tags can't be added.
  • default: false

isEditTagsModeEnabled

  • Enables tags edit mode.
  • default: true

tagRemoveButtonSvgId

  • String of svg id for tag remove button.
  • default: null

editTagInputPlaceholder

  • The edit tag placeholder text to display when the user hasn't typed anything.
  • default: 'Enter a tag...'

newTagInputPlaceholder

  • The new tag placeholder text to display when the user hasn't typed anything.
  • default: 'Add a tag...'

editTagInputMaxLength

  • The max length of text which can be entered to the edit tag input.
  • default: 'Enter a tag...'

newTagInputMaxLength

  • The max length of text which can be entered to the new tag input.
  • default: 'Add a tag...'

isAutoNewInputWidthEnabled

  • Enables auto width for new tag input.
  • default: true

isAutoEditInputWidthEnabled

  • Enables auto width for edit tag input.
  • default: true

showRemoveButtons

  • If 'x' removal links should be displayed at the right side of each tag.
  • default: true

Actions

onAddTag

Action which occurs when tag should be added.

onAddTags

Action which occurs when tags should be added.

onReplaceTagAtIndex

Action which occurs when tag should be replaced with a new tag.

onReplaceTagWithTagsAtIndex

Action which occurs when tag should be replaced with several new tags.

onRemoveTagAtIndex

Action which occurs when tag should be removed.

Package Sidebar

Install

npm i ember-tags-input

Weekly Downloads

1

Version

0.3.0

License

MIT

Unpacked Size

20.6 kB

Total Files

14

Last publish

Collaborators

  • alexey.bedonik