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

Button : deprecate isSmall prop #59734

Merged
merged 7 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

- `TextControl`: Add typings for `date`, `time` and `datetime-local` ([#59666](https://github.com/WordPress/gutenberg/pull/59666)).

### Deprecation

- `isSmall` prop in `Button` component has been deprecated. Use `size="small"` prop instead ([#59734](https://github.com/WordPress/gutenberg/pull/59734)).

### Internal

- `Button`: Keep deprecated props in type definitions ([#59913](https://github.com/WordPress/gutenberg/pull/59913)).
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ function useDeprecatedProps( {
};

if ( isSmall ) {
deprecated( 'Button isSmall prop', {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps the deprecated warning itself is unnecessary?

Yes, I personally don't think it's worth it in this particular case, but I'm not going to block it if you or others think it's warranted. I will suggest adding a Dev Note for the next WP release though.

If we're going to throw a warning, we should add a prefix:

Suggested change
deprecated( 'Button isSmall prop', {
deprecated( 'wp.components.Button isSmall prop', {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to remove the deprecated() function for now so it doesn't throw any warnings. In the future, we may need to consider adding warnings along with other props such as isPrimary|isTertiary|isSecondary|isLink.

since: '6.6',
alternative: 'size="small"',
} );
computedSize ??= 'small';
}

Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/button/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe( 'Button', () => {
} );

it( 'should render a button element with is-secondary and is-small class', () => {
render( <Button variant="secondary" isSmall /> );
render( <Button variant="secondary" size="small" /> );
const button = screen.getByRole( 'button' );

expect( button ).toHaveClass( 'is-secondary' );
Expand Down Expand Up @@ -586,6 +586,7 @@ describe( 'Button', () => {
it( 'should not break when the legacy isSmall prop is passed', () => {
render( <Button isSmall /> );
expect( screen.getByRole( 'button' ) ).toHaveClass( 'is-small' );
expect( console ).toHaveWarned();
} );

it( 'should have the is-small class when small class prop is passed', () => {
Expand Down
16 changes: 7 additions & 9 deletions packages/components/src/button/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@ type BaseButtonProps = {
* Renders a pressed button style.
*/
isPressed?: boolean;
// TODO: Deprecate officially (add console warning and move to DeprecatedButtonProps).
/**
* Decreases the size of the button.
*
* Deprecated in favor of the `size` prop. If both props are defined, the `size` prop will take precedence.
*
* @deprecated Use the `'small'` value on the `size` prop instead.
*/
isSmall?: boolean;
/**
* Sets the `aria-label` of the component, if none is provided.
* Sets the Tooltip content if `showTooltip` is provided.
Expand Down Expand Up @@ -184,6 +175,13 @@ export type DeprecatedButtonProps = {
* @ignore
*/
isTertiary?: boolean;
/**
* Decreases the size of the button.
*
* @deprecated Use the `'small'` value on the `size` prop instead.
* @ignore
*/
isSmall?: boolean;
};

export type DeprecatedIconButtonProps = {
Expand Down
Loading