From 78a4f34b04ef02980f3c02f619665c0627d26994 Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Date: Sat, 11 Feb 2023 14:25:06 +0530 Subject: [PATCH] feat(link-control): keep the setting opened --- .../src/components/link-control/index.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index a63723e463d813..7447c1e3dbef54 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -9,6 +9,8 @@ import classnames from 'classnames'; import { Button, Spinner, Notice } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { useRef, useState, useEffect } from '@wordpress/element'; +import { select, dispatch } from '@wordpress/data'; +import { store as preferencesStore } from '@wordpress/preferences'; import { focus } from '@wordpress/dom'; import { ENTER } from '@wordpress/keycodes'; @@ -136,7 +138,14 @@ function LinkControl( { const textInputRef = useRef(); const isEndingEditWithFocus = useRef( false ); - const [ settingsOpen, setSettingsOpen ] = useState( false ); + const isSettingsOpen = select( preferencesStore ).get( + 'core/editor', + 'linkControlSettingsOpen' + ); + + const [ settingsOpen, setSettingsOpen ] = useState( + isSettingsOpen || false + ); const [ internalUrlInputValue, setInternalUrlInputValue ] = useInternalInputValue( value?.url || '' ); @@ -192,6 +201,14 @@ function LinkControl( { isEndingEditWithFocus.current = false; }, [ isEditingLink, isCreatingPage ] ); + useEffect( () => { + dispatch( preferencesStore ).set( + 'core/editor', + 'linkControlSettingsOpen', + settingsOpen + ); + }, [ settingsOpen ] ); + const hasLinkValue = value?.url?.trim()?.length > 0; /**