Skip to content

Commit

Permalink
Use children and avoid prop drilling (#50963)
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave authored May 25, 2023
1 parent 1100545 commit 7eca021
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 53 deletions.
39 changes: 23 additions & 16 deletions packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { Button, Spinner, Notice } from '@wordpress/components';
import { Button, Spinner, Notice, TextControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useRef, useState, useEffect } from '@wordpress/element';
import { focus } from '@wordpress/dom';
Expand All @@ -19,6 +19,7 @@ import { isShallowEqualObjects } from '@wordpress/is-shallow-equal';
import LinkControlSettingsDrawer from './settings-drawer';
import LinkControlSearchInput from './search-input';
import LinkPreview from './link-preview';
import LinkSettings from './settings';
import useCreatePage from './use-create-page';
import useInternalValue from './use-internal-value';
import { ViewerFill } from './viewer-slot';
Expand Down Expand Up @@ -376,22 +377,28 @@ function LinkControl( {
<LinkControlSettingsDrawer
settingsOpen={ settingsOpen }
setSettingsOpen={ setSettingsOpen }
showTextControl={ showTextControl }
showSettings={ showSettings }
textInputRef={ textInputRef }
internalTextInputValue={
internalControlValue?.title
}
setInternalTextInputValue={
setInternalTextInputValue
}
handleSubmitWithEnter={ handleSubmitWithEnter }
value={ internalControlValue }
settings={ settings }
onChange={ createSetInternalSettingValueHandler(
settingsKeys
>
{ showTextControl && (
<TextControl
__nextHasNoMarginBottom
ref={ textInputRef }
className="block-editor-link-control__setting block-editor-link-control__text-content"
label="Text"
value={ internalControlValue?.title }
onChange={ setInternalTextInputValue }
onKeyDown={ handleSubmitWithEnter }
/>
) }
/>
{ showSettings && (
<LinkSettings
value={ internalControlValue }
settings={ settings }
onChange={ createSetInternalSettingValueHandler(
settingsKeys
) }
/>
) }
</LinkControlSettingsDrawer>
) }

<div className="block-editor-link-control__search-actions">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import {
Button,
TextControl,
__unstableMotion as motion,
__unstableAnimatePresence as AnimatePresence,
} from '@wordpress/components';
Expand All @@ -12,24 +11,7 @@ import { useReducedMotion, useInstanceId } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { Fragment } from '@wordpress/element';

/**
* Internal dependencies
*/
import Settings from './settings';

function LinkSettingsDrawer( {
settingsOpen,
setSettingsOpen,
showTextControl,
showSettings,
textInputRef,
internalTextInputValue,
setInternalTextInputValue,
handleSubmitWithEnter,
value,
settings,
onChange,
} ) {
function LinkSettingsDrawer( { children, settingsOpen, setSettingsOpen } ) {
const prefersReducedMotion = useReducedMotion();
const MaybeAnimatePresence = prefersReducedMotion
? Fragment
Expand Down Expand Up @@ -68,24 +50,7 @@ function LinkSettingsDrawer( {
} }
>
<div className="block-editor-link-control__drawer-inner">
{ showTextControl && (
<TextControl
__nextHasNoMarginBottom
ref={ textInputRef }
className="block-editor-link-control__setting block-editor-link-control__text-content"
label="Text"
value={ internalTextInputValue }
onChange={ setInternalTextInputValue }
onKeyDown={ handleSubmitWithEnter }
/>
) }
{ showSettings && (
<Settings
value={ value }
settings={ settings }
onChange={ onChange }
/>
) }
{ children }
</div>
</MaybeMotionDiv>
) }
Expand Down

1 comment on commit 7eca021

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 7eca021.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5081981590
📝 Reported issues:

Please sign in to comment.