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 request: Set max number of tags? #53

Open
clipartinc opened this issue Sep 19, 2023 · 1 comment
Open

Feature request: Set max number of tags? #53

clipartinc opened this issue Sep 19, 2023 · 1 comment

Comments

@clipartinc
Copy link

I'm wanting to set a max number of tags. Anyone know how to do this?

@clipartinc clipartinc changed the title Set max number of tags? Feature: Set max number of tags? Sep 19, 2023
@clipartinc clipartinc changed the title Feature: Set max number of tags? Feature request: Set max number of tags? Sep 19, 2023
@tomyedlp
Copy link

Not the best case but you can do this:

const [availableKeywords, setAvailableKeywords] = useState<string>("Max. 10 keywords")

useEffect(() => {
   setAvailableKeywords(keywords.length === 0 ? `Max. 10 keywords` : `${10-keywords.length} keywords left`)
}, [keywords])

const checkMaxLengthkeywords = () => {
   return keywords.length < 10 ? true : false
}

return (
  <TagsInput
      classNames={{tag: 'keywordTag', input: 'inputImg'}}
      value={keywords}
      onChange={setKeywords}
      name="keywords"
      separators={["Enter",","]}
      placeHolder={availableKeywords}
      beforeAddValidate={checkMaxLengthkeywords}
  />
)

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

No branches or pull requests

2 participants