Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Dynamic Tags render-tag prop #2526

Closed
OrbisK opened this issue Mar 1, 2022 · 1 comment · Fixed by #2592
Closed

Feature: Dynamic Tags render-tag prop #2526

OrbisK opened this issue Mar 1, 2022 · 1 comment · Fixed by #2592
Labels

Comments

@OrbisK
Copy link
Collaborator

OrbisK commented Mar 1, 2022

This function solves the problem (这个功能解决的问题)

Currently it is not possible to style tags individually.
E.g. i am using dynamic tags to add items to an array. I i want to hightlight tags which are duplicates like <n-tag type="warning" />

Expected API (期望的 API)

<n-dynamic-tags v-model:value="tags" :render-tag="renderTag"/>

const renderTag = (item)=> {
    return h(NTag, {type: item.length >=5 'warning' : 'default'}, ()=>item)
}

Or

<n-dynamic-tags v-model:value="tags" :tag-type="tagType"/>

const tagType= (item)=> {
    return item.length >=5 'warning' : 'default'
}

Or just a tag slot

@thichieuanh
Copy link

thichieuanh commented Apr 3, 2023

I got an issue when using custom render-tag. The validator didn't run when I clicked remove tag ('change' event was not triggered).

 <n-form :model="model" :rules="rules">
     <n-form-item path="tags" :show-label="false">
       <n-dynamic-tags v-model:value="model.tags" :render-tag="renderTag" />
     </n-form-item>
 </n-form>
 
    
 const model = ref({
        tags: ['teacher', 'programmer'],
 });
 
 
 const rules = ref({
    tags: {
       trigger: ['change'],
       validator(rule, value) {
         if (value.length >= 3) return new Error('Up to 4 tags');
         return true;
    },
  },
});

const renderTag = (tag, index) => {
  return h(
    NTag,
    {
      type: index < 3 ? 'success' : 'error',
      disabled: index > 3,
      closable: true,
      onClose: () => {
        model.value.tags.splice(index, 1);
      },
    },
    { default: () => tag },
  );
};


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants