Skip to content

Commit 83529aa

Browse files
committed
clear input field update
1 parent 2c38c45 commit 83529aa

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/index.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-labels */
2-
import React, { useState, useEffect } from 'react'
2+
import React, { useState, useEffect, useRef } from 'react'
33
import CloseIcon from './CloseIcon.jsx'
44
import DownIcon from './DownIcon.jsx'
55
import Options from './Options'
@@ -46,6 +46,7 @@ function MultiSelect({
4646
disableChip,
4747
name,
4848
attr,
49+
largeData,
4950
disabled,
5051
limit,
5152
emptyDataLabel,
@@ -55,6 +56,7 @@ function MultiSelect({
5556
const [value, setValue] = useState([])
5657
const [options, setOptions] = useState(userOptions || [])
5758
const [search, setSearch] = useState(null)
59+
const inputFld = useRef()
5860

5961
let stopPropagation = true
6062

@@ -267,10 +269,8 @@ function MultiSelect({
267269
}
268270
setNewValue(tmp)
269271
setSearch(null)
270-
271-
document
272-
.querySelectorAll('.msl-input')
273-
.forEach((input) => (input.innerHTML = ''))
272+
// clear input
273+
inputFld.current.innerHTML = ''
274274
}
275275

276276
const deleteValue = (i) => {
@@ -447,6 +447,7 @@ function MultiSelect({
447447
className='msl-input'
448448
contentEditable={!disabled}
449449
onKeyUp={searchValue}
450+
ref={inputFld}
450451
/>
451452
)}
452453
</div>
@@ -477,15 +478,29 @@ function MultiSelect({
477478
)}
478479
</div>
479480
<div className='msl-options'>
480-
{menuOpen && !search && options.length ? (
481+
{!search && options.length ? (
481482
<Options
482483
opts={options}
483-
{...{ singleSelect, addValue, checkValueExist, value }}
484+
{...{
485+
singleSelect,
486+
addValue,
487+
checkValueExist,
488+
value,
489+
largeData,
490+
menuOpen
491+
}}
484492
/>
485493
) : search && search.length ? (
486494
<Options
487495
opts={search}
488-
{...{ singleSelect, addValue, checkValueExist, value }}
496+
{...{
497+
singleSelect,
498+
addValue,
499+
checkValueExist,
500+
value,
501+
largeData,
502+
menuOpen
503+
}}
489504
/>
490505
) : (
491506
((search && !search.length) || (options && !options.length)) && (

0 commit comments

Comments
 (0)