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 2 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 @@ -6,6 +6,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)).

## 27.1.0 (2024-03-06)

### Bug Fix
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ 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"',
version: '6.9',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
version: '6.9',

I'm thinking we don't really have to do a hard deprecation on this one, since the maintenance cost is very low. What do you think?

Copy link
Member

@tyxla tyxla Mar 15, 2024

Choose a reason for hiding this comment

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

I think we should start following those more actively and actually clean them all up when they're due. With that in mind, I find them useful and I think they help reduce technical debt over time. scratch that, this comment explained that really well.

} );
computedSize ??= 'small';
}

Expand Down
7 changes: 5 additions & 2 deletions 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 @@ -588,9 +588,11 @@ describe( 'Button', () => {
expect( console ).toHaveWarned();
} );

it( 'should not break when the legacy isSmall prop is passed', () => {
it( 'should warn when the isSmall prop is passed', () => {
// @ts-expect-error
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 All @@ -599,6 +601,7 @@ describe( 'Button', () => {
} );

it( 'should prioritize the `size` prop over `isSmall`', () => {
// @ts-expect-error
render( <Button size="compact" isSmall /> );
expect( screen.getByRole( 'button' ) ).not.toHaveClass(
'is-small'
Expand Down
10 changes: 1 addition & 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 @@ -154,6 +145,7 @@ export type DeprecatedButtonProps = {
isPrimary?: boolean;
isSecondary?: boolean;
isTertiary?: boolean;
isSmall?: boolean;
};

export type DeprecatedIconButtonProps = {
Expand Down
Loading