@@ -26,8 +26,6 @@ import {
2626 convertListToString ,
2727} from "./Utils" ;
2828
29- import "dayjs/locale/en-gb" ; // Import the locale for dayjs
30-
3129import { MyDateTimePicker } from "./DatePicker" ;
3230
3331/** Merge multiple React refs into a single callback ref. */
@@ -39,7 +37,7 @@ function mergeRefs<T>(
3937 if ( typeof ref === "function" ) {
4038 ref ( node ) ;
4139 } else if ( ref && typeof ref === "object" ) {
42- ( ref as React . MutableRefObject < T | null > ) . current = node ;
40+ ( ref as React . RefObject < T | null > ) . current = node ;
4341 }
4442 }
4543 } ;
@@ -278,12 +276,15 @@ export default function SearchField({
278276
279277 function handleBackspaceKeyDown ( ) {
280278 if ( inputValue === "" && tokenEquations . length > 0 ) {
281- const updatedTokens = [ ... tokenEquations ] ;
282- const lastEquation = updatedTokens [ updatedTokens . length - 1 ] ;
279+ const lastEquation = tokenEquations [ tokenEquations . length - 1 ] ;
280+ let updatedTokens : SearchBarTokenEquation [ ] ;
283281 if ( lastEquation . items . length > 1 ) {
284- lastEquation . items = lastEquation . items . slice ( 0 , - 1 ) ;
282+ updatedTokens = [
283+ ...tokenEquations . slice ( 0 , - 1 ) ,
284+ { ...lastEquation , items : lastEquation . items . slice ( 0 , - 1 ) } ,
285+ ] ;
285286 } else {
286- updatedTokens . pop ( ) ;
287+ updatedTokens = tokenEquations . slice ( 0 , - 1 ) ;
287288 }
288289 handleEquationsVerification ( updatedTokens , setTokenEquations ) ;
289290 setFocusedTokenIndex ( null ) ;
@@ -295,13 +296,14 @@ export default function SearchField({
295296
296297 /** Submit the current input value as a new token. */
297298 function handleSubmit ( ) {
298- if ( inputValue && inputValue . trim ( ) ) {
299+ const trimmed = inputValue . trim ( ) ;
300+ if ( trimmed ) {
299301 const { nature, type } = getTokenMetadata (
300- inputValue . trim ( ) ,
302+ trimmed ,
301303 suggestions ,
302304 previousToken ,
303305 ) ;
304- handleTokenCreation ( inputValue . trim ( ) , nature , type ) ;
306+ handleTokenCreation ( trimmed , nature , type ) ;
305307 }
306308 }
307309
@@ -350,7 +352,7 @@ export default function SearchField({
350352 optionSelectedRef . current = option !== null ;
351353 } }
352354 onKeyDown = { ( e : React . KeyboardEvent < HTMLDivElement > ) => {
353- if ( e . key === "Enter" && inputValue && inputValue . trim ( ) ) {
355+ if ( e . key === "Enter" && inputValue . trim ( ) ) {
354356 if ( optionSelectedRef . current ) {
355357 optionSelectedRef . current = false ;
356358 return ;
0 commit comments