Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep the Link Control settings drawer persistent #47989

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 || '' );
Expand Down Expand Up @@ -192,6 +201,14 @@ function LinkControl( {
isEndingEditWithFocus.current = false;
}, [ isEditingLink, isCreatingPage ] );

useEffect( () => {
dispatch( preferencesStore ).set(
'core/editor',
'linkControlSettingsOpen',
settingsOpen
);
}, [ settingsOpen ] );

Comment on lines +204 to +211
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@getdave As per the comment you made on my earlier PR #47930 (comment)

I should not query the store in the component itself. So I might have to refactor the code.

const hasLinkValue = value?.url?.trim()?.length > 0;

/**
Expand Down