Skip to content

Commit 1746e7d

Browse files
committed
fix remaining issues
1 parent b53b3ff commit 1746e7d

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

src/components/icon-search-popover/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ const IconSearchPopover = props => {
199199
fr.onload = function( e ) {
200200
setIsDropping( false )
201201
const svgString = cleanSvgString( addCustomIconClass( e.target.result ) )
202+
203+
doAction( 'stackable.icon-search-popover.svg-upload', svgString )
202204
props.onChange( svgString )
203205
props.onClose()
204206
}

src/components/sortable-picker/index.js

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ const SortablePicker = props => {
104104
onChange={ item => onChangeItem( item ) }
105105
ItemPreview={ props.ItemPreview }
106106
ItemPicker={ props.ItemPicker }
107+
updateOnBlur={ props.updateOnBlur }
107108
/> ) ) }
108109
</SortableContainer>
109110
</div>
@@ -138,30 +139,18 @@ const LabeledItemIndicator = props => {
138139
onChange,
139140
ItemPreview = null,
140141
ItemPicker = null,
141-
enableDebounce = true, // If false, onChange will be called immediately.
142+
updateOnBlur = false, // If true, onChange will be called only when the input is blurred.
142143
} = props
143144

144145
const [ isFocused, setIsFocused ] = useState( false )
145-
146146
const [ debouncedText, setDebouncedText ] = useState( item.name )
147147

148+
// Updates the debounced text when the items get resorted.
148149
useEffect( () => {
149-
setDebouncedText( item.name )
150-
}, [ item.name ] )
151-
152-
useEffect( () => {
153-
let timeout
154-
if ( item.name !== debouncedText && enableDebounce ) {
155-
timeout = setTimeout( () => {
156-
onChange( {
157-
...item,
158-
name: debouncedText,
159-
} )
160-
}, 300 )
150+
if ( item.name !== debouncedText ) {
151+
setDebouncedText( item.name )
161152
}
162-
163-
return () => clearTimeout( timeout )
164-
}, [ debouncedText, onChange ] )
153+
}, [ item.name ] )
165154

166155
return (
167156
<HStack justify="space-between" className="stk-global-settings-color-picker__color-indicator-wrapper">
@@ -184,11 +173,12 @@ const LabeledItemIndicator = props => {
184173
<ItemPreview item={ item } />
185174
<input
186175
className="components-input-control__input"
187-
value={ debouncedText }
176+
value={ isFocused ? debouncedText : item.name }
188177
onChange={ ev => {
189-
if ( enableDebounce ) {
190-
setDebouncedText( ev.target.value )
191-
} else {
178+
setDebouncedText( ev.target.value )
179+
180+
// If we're not updating on blur, update the value immediately.
181+
if ( ! updateOnBlur ) {
192182
onChange( {
193183
...item,
194184
name: ev.target.value,
@@ -197,7 +187,18 @@ const LabeledItemIndicator = props => {
197187
} }
198188
onFocus={ () => setIsFocused( true ) }
199189
onBlur={ ev => {
200-
setIsFocused( false )
190+
if ( updateOnBlur ) {
191+
onChange( {
192+
...item,
193+
name: debouncedText,
194+
} )
195+
}
196+
197+
// Update isFocused after a delay to ensure onChange has finished if updating on blur.
198+
setTimeout( () => {
199+
setIsFocused( false )
200+
}, 100 )
201+
201202
if ( isOpen && ! ev.relatedTarget?.closest( '.components-popover' ) ) {
202203
onToggle()
203204
}

0 commit comments

Comments
 (0)