Skip to content

Commit

Permalink
FormTokenField: Add prop to remove bottom margin (#48609)
Browse files Browse the repository at this point in the history
* FormTokenField: remove margin bottom from help text

* Update Changelog

* Add new prop to test to fix failures

* Fix mistakes found in review

* Ensure bottom margin is removed when prop is true

* Replace CSS margin with Spacer

* Update changelog

* update version

* Update spacer conditional to be more readable

* Remove deprecation warning to be added later

* Tweak changelog

---------

Co-authored-by: Lena Morita <[email protected]>
  • Loading branch information
brookewp and mirka authored Mar 28, 2023
1 parent 6073967 commit a5d73b2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `CustomGradientPicker`: Convert to TypeScript ([#48929](https://github.com/WordPress/gutenberg/pull/48929)).
- `ColorPicker`: Convert to TypeScript ([#49214](https://github.com/WordPress/gutenberg/pull/49214)).
- `GradientPicker`: Convert to TypeScript ([#48316](https://github.com/WordPress/gutenberg/pull/48316)).
- `FormTokenField`: Add a `__nextHasNoMarginBottom` prop to start opting into the margin-free styles ([48609](https://github.com/WordPress/gutenberg/pull/48609)).

### Enhancements

Expand Down
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.5. (The prop can be safely removed once this happens.)

## Usage

Expand Down
13 changes: 10 additions & 3 deletions packages/components/src/form-token-field/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ 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';
import { Spacer } from '../spacer';

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

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

const instanceId = useInstanceId( FormTokenField );
Expand Down Expand Up @@ -716,17 +721,19 @@ export function FormTokenField( props: FormTokenFieldProps ) {
/>
) }
</div>
{ ! __nextHasNoMarginBottom && <Spacer marginBottom={ 2 } /> }
{ __experimentalShowHowTo && (
<p
<StyledHelp
id={ `components-form-token-suggestions-howto-${ instanceId }` }
className="components-form-token-field__help"
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
>
{ tokenizeOnSpace
? __(
'Separate with commas, spaces, or the Enter key.'
)
: __( 'Separate with commas or the Enter key.' ) }
</p>
</StyledHelp>
) }
</div>
);
Expand Down
7 changes: 0 additions & 7 deletions packages/components/src/form-token-field/style.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.components-form-token-field__input-container {
@include input-control();
width: 100%;
margin: 0 0 $grid-unit-10 0;
padding: 0;
cursor: text;

Expand Down Expand Up @@ -48,12 +47,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
1 change: 1 addition & 0 deletions packages/components/src/form-token-field/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const FormTokenFieldWithState = ( {
setSelectedValue( tokens );
onChange?.( tokens );
} }
__nextHasNoMarginBottom
/>
);
};
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 a5d73b2

Please sign in to comment.