react-packages

@react-packages/keywords

It’s React component to input some keywords for database indexing or the metadata of search engine. It has the interface to add or delete a keyword easily. The following animated image depicts how the component works.

Input Image

After you type a keyword then you type a separator character, such as comma, the keyword will be visually enclosed by a box and the separator itself is not displayed. You can delete a keyword by clicking “x” mark on the right of the keyword or you can press Del or Backspace key on keyboard when the keyword you want to delete has focus. You can move focus among keywords by pressing arrow keys (or other ones defined by option). Beside that, Home key is to set focus on the first keyword and End is for the last one.

Basic Usage

import React from 'react';
import Keywords from "@react-packages/keywords";

export default function KeywordsDemo() {
    return <form ...>
        <div className='mb-4'>
            <label className='block'>Keywords</label>
            <Keywords name='keywords' />
        </div>
        <button>Submit</button>
    </form>;
}

On server, if HTTP parameters are collected using FormData object, the statement formData.getAll("keywords") will return the array of inputed keywords.

More Options (using createInput function)

Keywords component exemplified in the previous section uses the default options and CSS. If you want some customizations, you must use createInput function.

createInput function takes one parameter which is an object that its properties are the settings for Keywords component. This function will return a component object which can be used as an element (used in JSX).

The setting object has the following properties (all properties are optional):

Keywords Component Props

All props are optional.