diff --git a/README.md b/README.md index 1d5aff6..3d63d29 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,29 @@ Widget supports both controlling options: by value and by state. If you explicit If true, then an enter / return keypress is passed on (after being used to autocomplete). Useful if you want to have the form submit as soon as a single value is chosen. +## renderOptionsList : func +#### Default value: `(markUp, plaintext) => markUp` +Accepts function that changes each option in the autocomplete list. `markUp` will be the original text (including the highlighting), while `plaintext` will be the pure-text value of the option. Example: +```JavaScript +import React from 'react'; +import TextInput from 'react-autocomplete-input'; + +class MyComponent extends React.Component { + + render() { + return { + return <> {markUp} + }} options={this.state.options} />; + } +} + +``` + +## expandUp: boolean +#### Default value: false +If true, option list "expands up", essentially moving the ul based on the size of the options displayed. +Useful if input is near/at the bottom of the page. + # Styles Customization By default styles are defined in `"react-autocomplete-input/dist/bundle.css"`, however, you may define your custom styles instead for following entities: diff --git a/src/AutoCompleteTextField.js b/src/AutoCompleteTextField.js index 406e663..f1c0dfb 100644 --- a/src/AutoCompleteTextField.js +++ b/src/AutoCompleteTextField.js @@ -47,6 +47,8 @@ const propTypes = { offsetX: PropTypes.number, offsetY: PropTypes.number, passThroughEnter: PropTypes.bool, + renderOptionsList: PropTypes.func, + expandUp: PropTypes.bool }; const defaultProps = { @@ -72,6 +74,8 @@ const defaultProps = { offsetY: 0, value: null, passThroughEnter: false, + renderOptionsList: (markUp, plaintext)=> markUp, + expandUp: false }; class AutocompleteTextField extends React.Component { @@ -429,6 +433,8 @@ class AutocompleteTextField extends React.Component { value, } = this.state; + const {renderOptionsList, expandUp} = this.props; + if (!helperVisible) { return null; } @@ -447,8 +453,11 @@ class AutocompleteTextField extends React.Component { const optionNumber = maxOptions === 0 ? options.length : maxOptions; + let height = offsetY; + const helperOptions = options.slice(0, optionNumber).map((val, idx) => { const highlightStart = val.toLowerCase().indexOf(value.substr(matchStart, matchLength).toLowerCase()); + height -= 52; return (
  • { this.handleSelection(idx); }} onMouseEnter={() => { this.setState({ selection: idx }); }} > - {val.slice(0, highlightStart)} - {val.substr(highlightStart, matchLength)} - {val.slice(highlightStart + matchLength)} + + {renderOptionsList(<>{val.slice(0, highlightStart)}{val.substr(highlightStart, matchLength)}{val.slice(highlightStart + matchLength)}, val)}
  • ); }); + if (!expandUp) { + height = top + offsetY; + } + return ( -