Skip to content

Commit

Permalink
feat: showAllValues on click
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Hall <jordan@libertyware.co.uk>
  • Loading branch information
Jordan-Hall committed Apr 22, 2022
1 parent 5c1014e commit 0bccc2b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4,073 deletions.
18 changes: 9 additions & 9 deletions src/lib/fragments/AutoComplete.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const AutoComplete = (props) => {
}

const handleComponentBlur = (newState, escape) => {
const focusOnBlur = escape && selectElement ? -1 : null
const focusOnBlur = escape && (selectElement || showAllValues) ? -1 : null
let newQuery
if (confirmOnBlur) {
newQuery = newState.query || query
Expand Down Expand Up @@ -248,7 +248,7 @@ const AutoComplete = (props) => {
// In this case they focus on the option before the selected one (or the last),
// and also make menu open
if (selectElement && isMenuOpen === false) {
source('', (options) => {
dataSource('', (options) => {
setMenuOpen(true);
setOptions(options);

Expand Down Expand Up @@ -277,7 +277,7 @@ const AutoComplete = (props) => {
// In this case they focus on the option after the selected one (or the first),
// and also make menu open
if (selectElement && !isMenuOpen) {
source('', (options) => {
dataSource('', (options) => {
setMenuOpen(true);
setOptions(options);
let index = query && options.indexOf(query) > -1 ? options.indexOf(query) + 1 : 0
Expand Down Expand Up @@ -335,7 +335,7 @@ const AutoComplete = (props) => {
handleOptionClick(event, selected)
}
} else if (selectElement) {
source('', (options) => {
dataSource('', (options) => {
setOptions(options)

let index = query && options.indexOf(query) > -1 ? options.indexOf(query) : 0
Expand Down Expand Up @@ -439,17 +439,17 @@ const AutoComplete = (props) => {
}

const handleInputClick = (event) => {
if (selectElement && isMenuOpen === false) {
if ((selectElement || showAllValues) && isMenuOpen === false) {
const newQuery = event.target.value
source('', (options) => {
dataSource('', (options) => {
const currentSelectionIndex = options.indexOf(newQuery)
setMenuOpen(true);
setOptions(options);
setFocus(currentSelectionIndex);
selected(currentSelectionIndex);
setSelected(currentSelectionIndex);
setHover(null);
})
} else if (selectElement) {
} else if (selectElement || showAllValues) {
handleComponentBlur({
menuOpen: false
}, true)
Expand Down Expand Up @@ -579,7 +579,7 @@ const AutoComplete = (props) => {
autoComplete='off'
className={`${inputClassName}${inputModifierFocused}${inputModifierType}`}
id={id}
onClick={(event) => handleInputClick(event)}
onClick={handleInputClick}
onBlur={handleInputBlur}
onChange={handleInputChange}
onFocus={handleInputFocus}
Expand Down
Loading

0 comments on commit 0bccc2b

Please sign in to comment.