1.5.0 • Published 6 years ago

typereact v1.5.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Typereact

CircleCI Travis npm version Coverage Status Greenkeeper badge

Typereact is a simple React typeahead component that supports grouped entries.

Typeahead example

Demo

You can find a demo here: https://visusnet.github.io/typereact/

Install

With npm:

npm i typereact

Or with yarn:

yarn add typereact

Usage

import Typeahead from 'typereact';

const handleBlur = (fieldName, value) => {
    console.log(`Field ${fieldName} set to ${value}.`)
};

<Typeahead options={options} onBlur={handleBlur} />

Configuration

PropRequiredDefaultDescription
allowUnknownValuefalsefalseIf true, arbitrary values can be typed.
autoSelectSingleOptionfalsefalseIf true, the component will automatically select an option if there are no other options available.
calculateGroupHeightfalse59 or 28A callback that returns the height of group entries in pixels. Parameters: group, index.
calculateListHeightfalse28 or min(300, number of options * 28)A callback that returns the height of the menu in pixels. Parameters: rows, totalRowsHeight.
calculateOptionHeightfalse28A callback that returns the height of option entries in pixels. Parameters: option, index.
estimateMenuWidthfalseundefinedEither a callback that returns the width the menu in pixels or a boolean value. Parameters: rows. If true, a default implementation is used that tries to estimate the menu width based on label length.
groupsfalseundefinedIf supplied, options will be grouped according to these groups.
idfalseundefinedSets the HTML input ID.
isClearablefalsefalseRenders a button that unsets the selected value if set to true.
isDisabledfalsefalseIf true, the component is disabled.
menuWidthfalseundefinedA number that manually sets the width of the menu.
notFoundLabelfalsenicht gefunden (German)A string that is displayed after the typed label for which no options could be found.
onBlurfalseno opA callback that is called when focus is lost. Parameters: fieldName, value.
onChangefalseno opA callback that is called when the value has changed. Parameters: fieldName, value.
optionsfalse[]An array of label-value-pairs.
placeholderfalse''Sets the HTML placeholder attribute.
renderEmptyGroupsfalsefalseIf true, groups will be rendered even if they don't have any options. Works only in conjunction with groups.
tabIndexfalseundefinedIf set, this prop is passed down to the input field.
valuefalseundefinedIf set, selects the option with the specified value.

Options

options must be an array with objects containing a label (string) and a value (can have any type), e.g.

{
  label: 'This will be shown',
  value: 'this is the value'
}

Groups

If you want your options to be grouped, you can set the groups prop which has the same structure as the options prop. In order to assign options to a group, you have to add an additional group property (of any type that matches the type of the group's value) to the options.

Example:

const options = [
    {label: 'First option in Group 1', value: 'firstOfGroup1', group: 'group1'},
    {label: 'Second option in Group 1', value: 'secondOfGroup1', group: 'group1'},
    {label: 'First option in Group 2', value: 'firstOfGroup2', group: 'group2'},
    {label: 'Second option in Group 2', value: 'secondOfGroup2', group: 'group2'}
];

const groups = [
    {label: 'Group 1', value: 'group1'},
    {label: 'Group 2', value: 'group2'}
];

Styling

You can apply your own styling or use the example that is used by the demo page.

License

MIT

1.5.0

6 years ago

1.4.3

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.3.0

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago