fix: Clear blocks modal search input when closing the modal (#2501)
This commit is contained in:
@@ -23,9 +23,20 @@ export const BlocksDrawer: React.FC<Props> = (props) => {
|
||||
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [filteredBlocks, setFilteredBlocks] = useState(blocks);
|
||||
const { closeModal } = useModal();
|
||||
const { closeModal, modalState } = useModal();
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
const { t, i18n } = useTranslation('fields');
|
||||
|
||||
useEffect(() => {
|
||||
setIsModalOpen(Boolean(modalState[drawerSlug]?.isOpen));
|
||||
}, [modalState, drawerSlug]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isModalOpen) {
|
||||
setSearchTerm('');
|
||||
}
|
||||
}, [isModalOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
const matchingBlocks = blocks.reduce((matchedBlocks, block) => {
|
||||
if (block.slug.toLowerCase().indexOf(searchTerm.toLowerCase()) !== -1) matchedBlocks.push(block);
|
||||
|
||||
Reference in New Issue
Block a user