Query:
I’m working with a component in Syncfusion, and I’m facing an issue.
Problem:
When I try to enter a value in the textbox, it keeps losing focus every time.
useCallback and React.memo, but the issue persists.focusIn method, but the behavior isn’t smooth—there’s a noticeable blinking every time.Request:
Could you please help me identify the root cause and suggest a solution to ensure the textbox retains its focus without the blinking effect?
But in html render approach,i can't use props of component like visible,prefixIconCss
is there any way to stop glitch of textbox while searching when we used with toolbarcomponent instead of html render approach
import { ToolbarComponent } from '@syncfusion/ej2-react-navigations'; import { useState, useEffect, useRef, useCallback, useMemo } from "react"; import * as React from "react"; import { createRoot } from 'react-dom/client'; import { TextBoxComponent } from '@syncfusion/ej2-react-inputs'; const SearchInput = React.memo(({ onInput }) => { const searchBoxRef = useRef(null); useEffect(() => { if (searchBoxRef.current) { searchBoxRef.current.addIcon('prepend', 'e-icons e-search pr-0'); searchBoxRef.current.addIcon('append', 'e-icons e-close'); searchBoxRef.current.focusIn(); } }, []); return ( <TextBoxComponent ref={searchBoxRef} input={onInput} placeholder="Search" /> ); }); const ReactApp = ({ selectedRecords = [] }) => { const ToolbarState = { DEFAULT: 'DEFAULT', SINGLE_SELECT: 'SINGLE_SELECT', MULTI_SELECT: 'MULTI_SELECT' }; const [toolbarState, setToolbarState] = useState(ToolbarState.DEFAULT); const [searchValue, setSearchValue] = useState(''); useEffect(() => { const state = selectedRecords.length > 1 ? ToolbarState.MULTI_SELECT : selectedRecords.length === 1 ? ToolbarState.SINGLE_SELECT : ToolbarState.DEFAULT; setToolbarState(state); }, [selectedRecords]); const handleVisibilty = useCallback((id) => { switch (id) { case 'cut': return toolbarState === ToolbarState.SINGLE_SELECT; case 'copy': return toolbarState === ToolbarState.MULTI_SELECT; case 'paste': return toolbarState === ToolbarState.DEFAULT; case 'bold': return toolbarState === ToolbarState.SINGLE_SELECT; case 'italic': return toolbarState === ToolbarState.MULTI_SELECT; default: return false; } }, [toolbarState]); const handleSearchInput = useCallback((e) => { setSearchValue(e.value); console.log(e.value); }, []); const searchInputTemplate = useCallback(() => ( <SearchInput onInput={handleSearchInput} /> ), [handleSearchInput]); const items = useMemo(() => [ { text: '', id: 'cut', template: searchInputTemplate, visible: [handleVisibilty('cut')] }, { text: 'MULTI_SELECT', id: 'copy', visible: [handleVisibilty('copy')] }, { text: 'DEFAULT', id: 'paste', visible: [handleVisibilty('paste')] }, { text: 'SINGLE_SELECT', id: 'bold', visible: [handleVisibilty('bold')] }, { text: 'MULTI_SELECT', id: 'italic', visible: [handleVisibilty('italic')] }, ], [searchInputTemplate, handleVisibilty]); return ( <ToolbarComponent items={items} /> ); }; |