Nurzhan Nogerbek
Nurzhan Nogerbek

Reputation: 5236

Change default behavior in TagInput element of Buefy library (Vue.js)?

In my Vue.js (version 2.5.22) application I use UI components from Buefy library. I use taginput element. If I have limit of 5 tags as in example below, borders dissapear when input has 5 tags.

QUESTION: Is it possible to change this behavior? I want to show borders anyway.

<b-field label="Limited to 10 characters and 5 tags">
    <b-taginput maxtags="5":value="['Red', 'Green', 'Blue', 'White']">
    </b-taginput>
</b-field>

Upvotes: 0

Views: 933

Answers (3)

Nurzhan Nogerbek
Nurzhan Nogerbek

Reputation: 5236

Well, in my case I use such style:

<b-field class="always-show" label="Limited to 10 characters and 5 tags">
    <b-taginput maxtags="5" :value="['Red', 'Green', 'Blue', 'White']">
    </b-taginput>
</b-field>

CSS:

.always-show .taginput-container {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    height: auto;
    cursor: text;
    border-color: #dbdbdb;
    color: #363636;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
    clear: both;
    font-size: 1rem;
    position: relative;
    text-align: left;
    border-radius: 4px;
    -webkit-box-shadow: inset 0 1px 2px rgba(10, 10, 10, 0.1);
    background-color: #fff;
    box-shadow: inset 0 1px 2px hsla(0,0%,4%,.1);
    padding: calc(.375em - 1px) calc(.625em - 1px);
    line-height: 1.5;
  }

Upvotes: 0

yujinpan
yujinpan

Reputation: 519

I have a suggestion, maybe a different way, you don't need to modify the default limit behavior:    1. Do not limit the number of labels entered.    2. Determine when adding, if it is more than 5, delete the first one.

  • template
<b-field label="Limited to 10 characters and 5 tags">
    <b-taginput @add="onAdd" :value="tags">
    </b-taginput>
</b-field>
  • js
data() {
  return {
    tags: []
  }
}
onAdd(){
  if (this.tags.length > 5) {
    this.tags.shift();
  }
}

Upvotes: 1

patapity
patapity

Reputation: 146

There isn't prop for this. You can add a class attrib to b-field component tag:

<b-field class="always-show" label="Limited to 10 characters and 5 tags">
    <b-taginput maxtags="5" :value="['Red', 'Green', 'Blue', 'White']">
    </b-taginput>
</b-field>

then add a style for new class:

.always-show .taginput-container{
  box-shadow: inset 0 1px 2px hsla(0,0%,4%,.1);
  border: 1px solid #b5b5b5;
  border-radius: 4px;
  padding: calc(.375em - 1px) calc(.625em - 1px);
}

Upvotes: 1

Related Questions