Skip to content

BaseControl: Deprecate bottom margin #38730

Closed
@mirka

Description

What problem does this address?

The BaseControl component currently has an inherent margin-bottom, making it hard to reuse in different contexts, since it requires a style override of an internal element. This kind of internal override is something we want to discourage.

Additionally, the current margin-bottom leads to inconsistent results when help text is supplied, because the margin is inserted before and not after the help text.

What is your proposed solution?

Deprecate the bottom margin (similar to #37160), following the guidelines stipulated in the devdocs.

Because this change impacts a large number of components (even just inside the Gutenberg codebase), I suggest we approach this in phases:

✍️ Dev Note (WordPress 6.2 release)

A number of UI components currently ship with styles that give them top and/or bottom margins. This can make it hard to reuse them in arbitrary layouts, where you want different amounts of gap or margin between components.

To better suit modern layout needs, we will gradually deprecate these outer margins. A deprecation will begin with an opt-in period where you can choose to apply the new margin-free styles on a given component instance. Eventually in a future version, the margins will be completely removed.

Continuing the effort started in previous releases, for the WordPress 6.2 release we focused on the BaseControl component and its consumers. While the effort is still ongoing, the outer margins on the following components have been deprecated.

  • BaseControl
  • CheckboxControl
  • ComboboxControl
  • FocalPointPicker
  • RadioControl
  • RangeControl
  • SearchControl
  • SelectControl
  • TextControl
  • TextareaControl
  • ToggleControl
  • ToggleGroupControl
  • TreeSelect

To start opting into the new margin-free styles, set the __nextHasNoMarginBottom prop to true.

<SelectControl
  options={ selectOptions }
  value={ selectValue }
  label={ __( 'Label' ) }
  onChange={ onSelectChange }
  __nextHasNoMarginBottom={ true }
/>

We're in the process of migrating all internal usages to use the new __nextHasNoMarginBottom prop. Once all usages are migrated, an official deprecation will be added to the BaseControl component

Metadata

Assignees

Labels

Needs Dev NoteRequires a developer note for a major WordPress release cycle[Package] Components/packages/components[Type] Tracking IssueTactical breakdown of efforts across the codebase and/or tied to Overview issues.

Type

No type

Projects

  • Status

    Done 🎉

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions