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

Navigation Link: Add "Open in new tab" toggle to navigation block sidebar #67262

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
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
62 changes: 40 additions & 22 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,43 @@ import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { createBlock } from '@wordpress/blocks';
import { useSelect, useDispatch } from '@wordpress/data';
import {
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
TextControl,
TextareaControl,
ToolbarButton,
Tooltip,
ToolbarGroup,
} from '@wordpress/components';
import { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';
import { __ } from '@wordpress/i18n';
import {
BlockControls,
InspectorControls,
RichText,
useBlockProps,
store as blockEditorStore,
getColorClassName,
useBlockProps,
useInnerBlocksProps,
} from '@wordpress/block-editor';
import { isURL, prependHTTP, safeDecodeURI } from '@wordpress/url';
import { useState, useEffect, useRef } from '@wordpress/element';
import { createBlock } from '@wordpress/blocks';
import {
TextControl,
TextareaControl,
ToggleControl,
ToolbarButton,
ToolbarGroup,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
Tooltip,
} from '@wordpress/components';
import { useMergeRefs, usePrevious } from '@wordpress/compose';
import { store as coreStore } from '@wordpress/core-data';
import { useDispatch, useSelect } from '@wordpress/data';
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
import { useEffect, useRef, useState } from '@wordpress/element';
import { decodeEntities } from '@wordpress/html-entities';
import { link as linkIcon, addSubmenu } from '@wordpress/icons';
import { store as coreStore } from '@wordpress/core-data';
import { useMergeRefs, usePrevious } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { addSubmenu, link as linkIcon } from '@wordpress/icons';
import { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';
import { isURL, prependHTTP, safeDecodeURI } from '@wordpress/url';

/**
* Internal dependencies
*/
import { getColors } from '../navigation/edit/utils';
import { LinkUI } from './link-ui';
import { updateAttributes } from './update-attributes';
import { getColors } from '../navigation/edit/utils';

const DEFAULT_BLOCK = { name: 'core/navigation-link' };

Expand Down Expand Up @@ -160,7 +161,7 @@ function getMissingText( type ) {
* Consider reuseing this components for both blocks.
*/
function Controls( { attributes, setAttributes, setIsLabelFieldFocused } ) {
const { label, url, description, title, rel } = attributes;
const { label, url, description, title, rel, opensInNewTab } = attributes;
return (
<ToolsPanel label={ __( 'Settings' ) }>
<ToolsPanelItem
Expand Down Expand Up @@ -204,7 +205,24 @@ function Controls( { attributes, setAttributes, setIsLabelFieldFocused } ) {
autoComplete="off"
/>
</ToolsPanelItem>

<ToolsPanelItem
hasValue={ () => !! opensInNewTab }
label={ __( 'Open in new tab' ) }
onDeselect={ () => setAttributes( { opensInNewTab: false } ) }
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Open in new tab' ) }
help={ __(
'The link will open in a new tab when clicked.'
) }
checked={ opensInNewTab }
onChange={ () =>
setAttributes( { opensInNewTab: ! opensInNewTab } )
}
/>
</ToolsPanelItem>
<ToolsPanelItem
hasValue={ () => !! description }
label={ __( 'Description' ) }
Expand Down
Loading