Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

React tagInput component

const TagInput = ({ tags }) => {
  const [tagData, setTagData] = React.useState(tags);
  const removeTagData = indexToRemove => {
    setTagData([...tagData.filter((_, index) => index !== indexToRemove)]);
  };
  const addTagData = event => {
    if (event.target.value !== '') {
      setTagData([...tagData, event.target.value]);
      event.target.value = '';
    }
  };
  return (
    <div className="tag-input">
      <ul className="tags">
        {tagData.map((tag, index) => (
          <li key={index} className="tag">
            <span className="tag-title">{tag}</span>
            <span
              className="tag-close-icon"
              onClick={() => removeTagData(index)}
            >
              x
            </span>
          </li>
        ))}
      </ul>
      <input
        type="text"
        onKeyUp={event => (event.key === 'Enter' ? addTagData(event) : null)}
        placeholder="Press enter to add a tag"
      />
    </div>
  );
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: enable vue devtools 
Javascript :: puppeteer wait for page loadjavascript 
Javascript :: fullcalendar react add event duration 
Javascript :: forof 
Javascript :: js array.splice first element 
Javascript :: delete a label jquer 
Javascript :: how to add cdn link in shopify 
Javascript :: get methods on an js object 
Javascript :: if keypress javascript 
Javascript :: javascript range between two numbers 
Javascript :: rich editor react 
Javascript :: getelementbyid js 
Javascript :: replace in javascript 
Javascript :: get an element from outside of iframe jquery 
Javascript :: js use restrict 
Javascript :: JS iterate over an array 
Javascript :: node js vs jquery 
Javascript :: js add function to array 
Javascript :: javascript get client page title 
Javascript :: javascript promise example basic 
Javascript :: await loop javascript 
Javascript :: node terminal readline console 
Javascript :: react bootstrap button 
Javascript :: How to create sequelize connection in javascript 
Javascript :: named regex group JS 
Javascript :: Comment intégrer font awesome et bootstrap dans angular 13 
Javascript :: move item to end of array for of 
Javascript :: jquery get custom attribute 
Javascript :: chart js two layer label 
Javascript :: vue axios post return json data 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =