mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-04 22:38:43 +00:00
fix issue,
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect, useRef } from 'react';
|
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import './combobox.less';
|
import './combobox.less';
|
||||||
|
|
||||||
@@ -16,6 +16,7 @@ const Combobox = ({
|
|||||||
},
|
},
|
||||||
valuePatterns = /.+/,
|
valuePatterns = /.+/,
|
||||||
options = [],
|
options = [],
|
||||||
|
keepValueOnClose = false,
|
||||||
...props
|
...props
|
||||||
})=>{
|
})=>{
|
||||||
const dropdownRef = useRef(null);
|
const dropdownRef = useRef(null);
|
||||||
@@ -30,15 +31,23 @@ const Combobox = ({
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleClickOutside = (e)=>{
|
const handleClickOutside = useCallback((e)=>{
|
||||||
// Close dropdown when clicked outside
|
// Close dropdown when clicked outside
|
||||||
if(!dropdownRef.current?.contains(e.target)) handleDropdown(false);
|
if(!dropdownRef.current?.contains(e.target)) {
|
||||||
};
|
handleDropdown(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleDropdown = (show)=>{
|
const handleDropdown = (show)=>{
|
||||||
setValue(show ? '' : defaultValue);
|
if(show) {
|
||||||
|
if(autoSuggest.clearAutoSuggestOnClick) {
|
||||||
|
setValue('');
|
||||||
|
}
|
||||||
|
} else if(!keepValueOnClose) {
|
||||||
|
setValue(defaultValue);
|
||||||
|
}
|
||||||
setShowDropdown(show);
|
setShowDropdown(show);
|
||||||
setInputFocused(autoSuggest.clearAutoSuggestOnClick ? show : false);
|
setInputFocused(autoSuggest.clearAutoSuggestOnClick && show);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleInput = (e)=>{
|
const handleInput = (e)=>{
|
||||||
|
|||||||
@@ -262,6 +262,7 @@ const MetadataEditor = ({
|
|||||||
id='combobox-language'
|
id='combobox-language'
|
||||||
className='language-dropdown'
|
className='language-dropdown'
|
||||||
defaultValue={metadata.lang || ''}
|
defaultValue={metadata.lang || ''}
|
||||||
|
keepValueOnClose={true}
|
||||||
placeholder='en'
|
placeholder='en'
|
||||||
onSelect={(value)=>handleLanguage(value)}
|
onSelect={(value)=>handleLanguage(value)}
|
||||||
onEntry={(e)=>{
|
onEntry={(e)=>{
|
||||||
|
|||||||
Reference in New Issue
Block a user