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

FormTokenField: Deprecate bottom margin #63491

Merged
merged 8 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function AuthorControl( { value, onChange } ) {
suggestions={ authorsInfo.names }
onChange={ onAuthorChange }
__experimentalShowHowTo={ false }
__nextHasNoMarginBottom
__next40pxDefaultSize
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export default function QueryInspectorControls( props ) {
) }
{ ! inherit && showFiltersPanel && (
<ToolsPanel
className="block-library-query-toolspanel__filters"
className="block-library-query-toolspanel__filters" // unused but kept for backward compatibility
label={ __( 'Filters' ) }
resetAll={ () => {
setQuery( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function ParentControl( { parents, postType, onChange } ) {
suggestions={ suggestions }
onChange={ onParentChange }
__experimentalShowHowTo={ false }
__nextHasNoMarginBottom
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* WordPress dependencies
*/
import { FormTokenField } from '@wordpress/components';
import {
FormTokenField,
__experimentalVStack as VStack,
} from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { useState, useEffect } from '@wordpress/element';
Expand Down Expand Up @@ -53,7 +56,7 @@ export function TaxonomyControls( { onChange, query } ) {
}

return (
<>
<VStack spacing={ 4 }>
{ taxonomies.map( ( taxonomy ) => {
const termIds = taxQuery?.[ taxonomy.slug ] || [];
const handleChange = ( newTermIds ) =>
Expand All @@ -73,7 +76,7 @@ export function TaxonomyControls( { onChange, query } ) {
/>
);
} ) }
</>
</VStack>
);
}

Expand Down Expand Up @@ -187,6 +190,7 @@ function TaxonomyItem( { taxonomy, termIds, onChange } ) {
displayTransform={ decodeEntities }
onChange={ onTermsChange }
__experimentalShowHowTo={ false }
__nextHasNoMarginBottom
__next40pxDefaultSize
/>
</div>
Expand Down
9 changes: 0 additions & 9 deletions packages/block-library/src/query/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@
}
}

.block-library-query-toolspanel__filters {
Copy link
Member

Choose a reason for hiding this comment

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

We're still rendering the original classname for backward compatibility, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. I added a code comment b912e8b

.components-form-token-field__help {
margin-bottom: 0;
}
.block-library-query-inspector__taxonomy-control:not(:last-child) {
margin-bottom: $grid-unit-30;
}
}

.wp-block-query__enhanced-pagination-modal {
@include break-small() {
max-width: $break-mobile;
Expand Down
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Deprecations

- `FormTokenField`: Deprecate bottom margin. Add a `__nextHasNoMarginBottom` prop to start opting into the margin-free styles that will become the default in a future version, currently scheduled to be WordPress 7.0 ([#63491](https://github.com/WordPress/gutenberg/pull/63491)).

### Bug Fixes

- `ComboboxControl`: Fix ComboboxControl reset button when using the keyboard. ([#63410](https://github.com/WordPress/gutenberg/pull/63410))
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/form-token-field/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The `value` property is handled in a manner similar to controlled form component
- `__experimentalShowHowTo` - If false, the text on how to use the select (ie: _Separate with commas or the Enter key._) will be hidden.
- `__experimentalValidateInput` - If passed, all introduced values will be validated before being added as tokens.
- `__experimentalAutoSelectFirstMatch` - If true, the select the first matching suggestion when the user presses the Enter key (or space when tokenizeOnSpace is true).
- `__nextHasNoMarginBottom` - Start opting into the new margin-free styles that will become the default in a future version, currently scheduled to be WordPress 6.5. (The prop can be safely removed once this happens.)
- `__nextHasNoMarginBottom` - Start opting into the new margin-free styles that will become the default in a future version, currently scheduled to be WordPress 7.0. (The prop can be safely removed once this happens.)
- `tokenizeOnBlur` - If true, add any incompleteTokenValue as a new token when the field loses focus.

## Usage
Expand All @@ -87,6 +87,7 @@ const MyFormTokenField = () => {
value={ selectedContinents }
suggestions={ continents }
onChange={ ( tokens ) => setSelectedContinents( tokens ) }
__nextHasNoMarginBottom
/>
);
};
Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/form-token-field/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { __, _n, sprintf } from '@wordpress/i18n';
import { useDebounce, useInstanceId, usePrevious } from '@wordpress/compose';
import { speak } from '@wordpress/a11y';
import isShallowEqual from '@wordpress/is-shallow-equal';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
Expand Down Expand Up @@ -77,6 +78,14 @@ export function FormTokenField( props: FormTokenFieldProps ) {
tokenizeOnBlur = false,
} = useDeprecated36pxDefaultSizeProp< FormTokenFieldProps >( props );

if ( ! __nextHasNoMarginBottom ) {
deprecated( 'Bottom margin styles for wp.components.FormTokenField', {
since: '6.7',
version: '7.0',
hint: 'Set the `__nextHasNoMarginBottom` prop to true to start opting into the new styles, which will become the default in a future version.',
} );
}

const instanceId = useInstanceId( FormTokenField );

// We reset to these initial values again in the onBlur
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const Default: StoryFn< typeof FormTokenField > = DefaultTemplate.bind(
Default.args = {
label: 'Type a continent',
suggestions: continents,
__nextHasNoMarginBottom: true,
};

export const Async: StoryFn< typeof FormTokenField > = ( {
Expand Down Expand Up @@ -99,6 +100,7 @@ export const Async: StoryFn< typeof FormTokenField > = ( {
Async.args = {
label: 'Type a continent',
suggestions: continents,
__nextHasNoMarginBottom: true,
Copy link
Member

Choose a reason for hiding this comment

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

Confirmed that all stories inherit args from either of the 2 definitions that define __nextHasNoMarginBottom: true.

};

export const DropdownSelector: StoryFn< typeof FormTokenField > =
Expand Down
4 changes: 4 additions & 0 deletions packages/editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Deprecations

- `PostTaxonomiesFlatTermSelector`: Deprecate bottom margin. Add a `__nextHasNoMarginBottom` prop to start opting into the margin-free styles that will become the default in a future version, currently scheduled to be WordPress 7.0 ([#63491](https://github.com/WordPress/gutenberg/pull/63491)).

## 14.3.0 (2024-07-10)

## 14.2.0 (2024-06-26)
Expand Down
1 change: 1 addition & 0 deletions packages/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,7 @@ _Parameters_

- _props_ `Object`: The component props.
- _props.slug_ `string`: The slug of the taxonomy.
- _props.\_\_nextHasNoMarginBottom_ `boolean`: Start opting into the new margin-free styles that will become the default in a future version, currently scheduled to be WordPress 7.0. (The prop can be safely removed once this happens.)

_Returns_

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const TagsPanel = () => {
'Tags help users and search engines navigate your site and find your content. Add a few keywords to describe your post.'
) }
</p>
<FlatTermSelector slug="post_tag" />
<FlatTermSelector slug="post_tag" __nextHasNoMarginBottom />
</PanelBody>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { __, _x, sprintf } from '@wordpress/i18n';
import { useEffect, useMemo, useState } from '@wordpress/element';
import { FormTokenField, withFilters } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import deprecated from '@wordpress/deprecated';
import { store as coreStore } from '@wordpress/core-data';
import { useDebounce } from '@wordpress/compose';
import { speak } from '@wordpress/a11y';
Expand Down Expand Up @@ -55,16 +56,28 @@ const termNamesToIds = ( names, terms ) => {
/**
* Renders a flat term selector component.
*
* @param {Object} props The component props.
* @param {string} props.slug The slug of the taxonomy.
* @param {Object} props The component props.
* @param {string} props.slug The slug of the taxonomy.
* @param {boolean} props.__nextHasNoMarginBottom Start opting into the new margin-free styles that will become the default in a future version, currently scheduled to be WordPress 7.0. (The prop can be safely removed once this happens.)
*
* @return {JSX.Element} The rendered flat term selector component.
*/
export function FlatTermSelector( { slug } ) {
export function FlatTermSelector( { slug, __nextHasNoMarginBottom } ) {
const [ values, setValues ] = useState( [] );
const [ search, setSearch ] = useState( '' );
const debouncedSearch = useDebounce( setSearch, 500 );

if ( ! __nextHasNoMarginBottom ) {
deprecated(
'Bottom margin styles for wp.editor.PostTaxonomiesFlatTermSelector',
{
since: '6.7',
Copy link
Member

Choose a reason for hiding this comment

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

Is this going to land in 6.7 actually?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, too late to land in 6.6.

version: '7.0',
hint: 'Set the `__nextHasNoMarginBottom` prop to true to start opting into the new styles, which will become the default in a future version.',
}
);
}

const {
terms,
termIds,
Expand Down Expand Up @@ -290,6 +303,7 @@ export function FlatTermSelector( { slug } ) {
removed: termRemovedLabel,
remove: removeTermLabel,
} }
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
/>
<MostUsedTerms taxonomy={ taxonomy } onSelect={ appendTerm } />
</>
Expand Down
9 changes: 8 additions & 1 deletion packages/editor/src/components/post-taxonomies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ export function PostTaxonomies( { taxonomyWrapper = identity } ) {
const TaxonomyComponent = taxonomy.hierarchical
? HierarchicalTermSelector
: FlatTermSelector;
const taxonomyComponentProps = {
slug: taxonomy.slug,
...( taxonomy.hierarchical
? {}
: { __nextHasNoMarginBottom: true } ),
};

return (
<Fragment key={ `taxonomy-${ taxonomy.slug }` }>
{ taxonomyWrapper(
<TaxonomyComponent slug={ taxonomy.slug } />,
<TaxonomyComponent { ...taxonomyComponentProps } />,
taxonomy
) }
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}
}

p:not(.components-base-control__help) {
p:not(.components-base-control__help, .components-form-token-field__help) {
margin-top: 0;
}
Comment on lines +36 to 38
Copy link
Member Author

Choose a reason for hiding this comment

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

This is to maintain this margin right here, which was previously maintained implicitly due to a Spacer component inserted in the __nextHasNoMarginBottom={ false } case.

Margin between FormTokenField input field and help text, in sidebar


Expand Down
Loading