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

Fix: Add the border width on initial color change for border #69112

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- `ComboboxControl`: Add an `isLoading` prop to show a loading spinner ([#68990](https://github.com/WordPress/gutenberg/pull/68990))
- `BorderControl`: adjust `useBorderControlDropdown` hook to use `1px` width when selecting the border color initially without explicitly setting width ([#69112](https://github.com/WordPress/gutenberg/pull/69112)).

## 29.3.0 (2025-01-29)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export function useBorderControlDropdown(
} = useContextSystem( props, 'BorderControlDropdown' );

const [ widthValue ] = parseQuantityAndUnitFromRawValue( border?.width );
const hasZeroWidth = widthValue === 0;
// If widthValue is 0, or on initial render we have width undefined.
// Need to set width to `1px`, if we change color first before adding border width.
const hasZeroWidth = widthValue === 0 || undefined === widthValue;

Choose a reason for hiding this comment

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

Use YODA condition:

Suggested change
const hasZeroWidth = widthValue === 0 || undefined === widthValue;
const hasZeroWidth = 0 === widthValue || undefined === widthValue;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @coder-rancho, Thanks for pointing this out, but new coding standards proposes not to use Yoda Conditions. The codebase have bunch of files that are not using Yoda conditions. I would update the PR if core team want's to use Yoda condition here.

Thank You,


const onColorChange = ( color?: string ) => {
const style =
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/border-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ describe( 'BorderControl', () => {
expect( props.onChange ).toHaveBeenCalledWith( {
color: '#bd8600',
style: undefined,
width: undefined,
width: '1px',
} );

await user.type( getWidthInput(), '0' );
Expand Down Expand Up @@ -478,7 +478,7 @@ describe( 'BorderControl', () => {
expect( props.onChange ).toHaveBeenCalledWith( {
color: undefined,
style: 'dashed',
width: undefined,
width: '1px',
} );

await user.type( getWidthInput(), '0' );
Expand Down
Loading