-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix toggle new tab does not persist changes to text input in Link Control #50401
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 31 additions & 83 deletions
114
packages/block-editor/src/components/link-control/settings-drawer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,45 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
Button, | ||
TextControl, | ||
__unstableMotion as motion, | ||
__unstableAnimatePresence as AnimatePresence, | ||
} from '@wordpress/components'; | ||
import { settings as settingsIcon } from '@wordpress/icons'; | ||
import { useReducedMotion, useInstanceId } from '@wordpress/compose'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { Fragment } from '@wordpress/element'; | ||
import { ToggleControl, VisuallyHidden } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Settings from './settings'; | ||
const noop = () => {}; | ||
|
||
function LinkSettingsDrawer( { | ||
settingsOpen, | ||
setSettingsOpen, | ||
showTextControl, | ||
showSettings, | ||
textInputRef, | ||
internalTextInputValue, | ||
setInternalTextInputValue, | ||
handleSubmitWithEnter, | ||
const LinkControlSettingsDrawer = ( { | ||
value, | ||
settings, | ||
onChange, | ||
} ) { | ||
const prefersReducedMotion = useReducedMotion(); | ||
const MaybeAnimatePresence = prefersReducedMotion | ||
? Fragment | ||
: AnimatePresence; | ||
const MaybeMotionDiv = prefersReducedMotion ? 'div' : motion.div; | ||
setNewValue = noop, | ||
} ) => { | ||
if ( ! settings || ! settings.length ) { | ||
return null; | ||
} | ||
|
||
const id = useInstanceId( LinkSettingsDrawer ); | ||
const handleSettingChange = ( setting ) => ( newValue ) => { | ||
setNewValue( { | ||
...value, | ||
[ setting.id ]: newValue, | ||
} ); | ||
}; | ||
|
||
const settingsDrawerId = `link-control-settings-drawer-${ id }`; | ||
const theSettings = settings.map( ( setting ) => ( | ||
<ToggleControl | ||
className="block-editor-link-control__setting" | ||
key={ setting.id } | ||
label={ setting.title } | ||
onChange={ handleSettingChange( setting ) } | ||
checked={ value ? !! value[ setting.id ] : false } | ||
/> | ||
) ); | ||
|
||
return ( | ||
<> | ||
<Button | ||
className="block-editor-link-control__drawer-toggle" | ||
aria-expanded={ settingsOpen } | ||
onClick={ () => setSettingsOpen( ! settingsOpen ) } | ||
icon={ settingsIcon } | ||
label={ __( 'Link Settings' ) } | ||
aria-controls={ settingsDrawerId } | ||
/> | ||
<MaybeAnimatePresence> | ||
{ settingsOpen && ( | ||
<MaybeMotionDiv | ||
className="block-editor-link-control__drawer" | ||
hidden={ ! settingsOpen } | ||
id={ settingsDrawerId } | ||
initial="collapsed" | ||
animate="open" | ||
exit="collapsed" | ||
variants={ { | ||
open: { opacity: 1, height: 'auto' }, | ||
collapsed: { opacity: 0, height: 0 }, | ||
} } | ||
transition={ { | ||
duration: 0.1, | ||
} } | ||
> | ||
<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 } | ||
/> | ||
) } | ||
</div> | ||
</MaybeMotionDiv> | ||
) } | ||
</MaybeAnimatePresence> | ||
</> | ||
<fieldset className="block-editor-link-control__settings"> | ||
<VisuallyHidden as="legend"> | ||
{ __( 'Currently selected link settings' ) } | ||
</VisuallyHidden> | ||
{ theSettings } | ||
</fieldset> | ||
); | ||
} | ||
}; | ||
|
||
export default LinkSettingsDrawer; | ||
export default LinkControlSettingsDrawer; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go with this route we can curry the function to pre-apply the handlers. That way you can just pass the new
value
to the curried function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored the
__newOnChangeForLinkControl
to call it just with the values in 91306d3.