Skip to content

Commit

Permalink
FormTokenField: remove margin bottom from help text
Browse files Browse the repository at this point in the history
  • Loading branch information
brookewp committed Mar 1, 2023
1 parent 73881d6 commit ccc8bc3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/components/src/form-token-field/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +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.4. (The prop can be safely removed once this happens.)

## Usage

Expand Down
22 changes: 18 additions & 4 deletions packages/components/src/form-token-field/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { KeyboardEvent, MouseEvent, TouchEvent } from 'react';
/**
* WordPress dependencies
*/
import deprecated from '@wordpress/deprecated';
import { useEffect, useRef, useState } from '@wordpress/element';
import { __, _n, sprintf } from '@wordpress/i18n';
import { useDebounce, useInstanceId, usePrevious } from '@wordpress/compose';
Expand All @@ -22,7 +23,10 @@ import { TokensAndInputWrapperFlex } from './styles';
import SuggestionsList from './suggestions-list';
import type { FormTokenFieldProps, TokenItem } from './types';
import { FlexItem } from '../flex';
import { StyledLabel } from '../base-control/styles/base-control-styles';
import {
StyledHelp,
StyledLabel,
} from '../base-control/styles/base-control-styles';

const identity = ( value: string ) => value;

Expand Down Expand Up @@ -67,8 +71,17 @@ export function FormTokenField( props: FormTokenFieldProps ) {
__experimentalShowHowTo = true,
__next36pxDefaultSize = false,
__experimentalAutoSelectFirstMatch = false,
__nextHasNoMarginBottom = false,
} = props;

if ( ! __nextHasNoMarginBottom ) {
deprecated( 'Bottom margin styles for wp.blockEditor.URLInput', {
since: '6.2',
version: '6.5',
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 Expand Up @@ -714,16 +727,17 @@ export function FormTokenField( props: FormTokenFieldProps ) {
) }
</div>
{ __experimentalShowHowTo && (
<p
<StyledHelp
id={ `components-form-token-suggestions-howto-${ instanceId }` }
className="components-form-token-field__help"
className="components-base-control__help"
__nextHasNoMarginBottom
>
{ tokenizeOnSpace
? __(
'Separate with commas, spaces, or the Enter key.'
)
: __( 'Separate with commas or the Enter key.' ) }
</p>
</StyledHelp>
) }
</div>
);
Expand Down
6 changes: 0 additions & 6 deletions packages/components/src/form-token-field/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@
}
}

.components-form-token-field__help {
font-size: $helptext-font-size;
font-style: normal;
color: $gray-700;
}

// Tokens
.components-form-token-field__token {
font-size: $default-font-size;
Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/form-token-field/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ export interface FormTokenFieldProps
* Custom renderer for suggestions.
*/
__experimentalRenderItem?: ( args: { item: string } ) => ReactNode;
/**
* Start opting into the new margin-free styles that will become the default in a future version.
*
* @default false
*/
__nextHasNoMarginBottom?: boolean;
}

/**
Expand Down

0 comments on commit ccc8bc3

Please sign in to comment.