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

BorderControl: always show Reset button #69066

Merged
merged 11 commits into from
Feb 15, 2025
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 @@ -2,13 +2,17 @@

## Unreleased

### Enhancements

- `ComboboxControl`: Add an `isLoading` prop to show a loading spinner ([#68990](https://github.com/WordPress/gutenberg/pull/68990))
- `BorderControlDropdown`, `BorderControl`: Reset button is always visible. ([#69066](https://github.com/WordPress/gutenberg/pull/69066)).

## 29.3.0 (2025-01-29)

### Enhancements

- `BorderBoxControl`, `BoxControl`: Remove `Tooltip` component from linked button ([#68498](https://github.com/WordPress/gutenberg/pull/68498)).
- `BorderControlDropdown`, `BorderControl`: Reset button is always visible. ([#69066](https://github.com/WordPress/gutenberg/pull/69066)).

### Internal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const BorderControlDropdown = (
onStyleChange,
popoverContentClassName,
popoverControlsClassName,
resetButtonClassName,
clearButtonClassName,
size,
__unstablePopoverProps,
...otherProps
Expand Down Expand Up @@ -199,9 +199,7 @@ const BorderControlDropdown = (
</Button>
);

const renderContent: DropdownComponentProps[ 'renderContent' ] = ( {
onClose,
} ) => (
const renderContent: DropdownComponentProps[ 'renderContent' ] = () => (
<>
<DropdownContentWrapper paddingSize="medium">
<VStack className={ popoverControlsClassName } spacing={ 6 }>
Expand All @@ -224,22 +222,20 @@ const BorderControlDropdown = (
/>
) }
</VStack>
</DropdownContentWrapper>
{ showResetButton && (
<DropdownContentWrapper paddingSize="none">
<div className={ clearButtonClassName }>
<Button
className={ resetButtonClassName }
variant="tertiary"
onClick={ () => {
onReset();
onClose();
} }
disabled={ ! showResetButton }
accessibleWhenDisabled
__next40pxDefaultSize
>
{ __( 'Reset' ) }
{ __( 'Clear' ) }
</Button>
</DropdownContentWrapper>
) }
</div>
</DropdownContentWrapper>
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these DOM / layout changes necessary?

  • Adding an extra div around the reset button
  • moving the reset button as a child of DropdownContentWrapper
  • renaming and restyling the reset button to the clear button?

In other words, it seems to me that the main issue was the "reset" button being added and removed from the DOM.

If we change the logic from

{ showResetButton && (
  <DropdownContentWrapper paddingSize="none">
    <Button {...buttonProps} />
  </DropdownContentWrapper>
) }

to

<DropdownContentWrapper paddingSize="none">
  <Button {...buttonProps} accessibleWhenDisabled disabled={!showResetButton}/>
</DropdownContentWrapper>

wouldn't that be enough?

Is the change from "Reset" to "Clear" necessary, including the UI/layout change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review!

Are these DOM / layout changes necessary?

const actions = actionsProp ? (
<div className="components-circular-option-picker__custom-clear-wrapper">
{ actionsProp }
</div>
) : undefined;

I think this is necessary to align the button to the right.
I used circular-option-picker as a reference.

renaming and restyling the reset button to the clear button?

This was also based on circular-option-picker.

CircularOptionPicker

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ciampo
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I may be missing context, but was there a specific request to make it look like CircularOptionPicker?

If the main need for this PR is to fix UI jumpiness and a11y around a button being added/removed from the DOM, then I'd keep design changes out of the PR scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the reply. Indeed, I changed Clear back to Reset as it was not a good idea to include it in this PR!
border

Copy link
Contributor

Choose a reason for hiding this comment

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

There are still design differences compared to what's on trunk, but I think they're probably the lowest effort we can make to keep the design working — if we kept the "reset" button to be full-width and with no left/right/bottom margins, the focus styles would be weird, and require even more hacky style overrides.

</>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export function useBorderControlDropdown(
return cx( styles.borderControlPopoverContent );
}, [ cx ] );

const resetButtonClassName = useMemo( () => {
return cx( styles.resetButton );
const clearButtonClassName = useMemo( () => {
return cx( styles.clearButton );
}, [ cx ] );

return {
Expand All @@ -94,7 +94,7 @@ export function useBorderControlDropdown(
onReset,
popoverContentClassName,
popoverControlsClassName,
resetButtonClassName,
clearButtonClassName,
size,
__experimentalIsRenderedInSidebar,
};
Expand Down
14 changes: 4 additions & 10 deletions packages/components/src/border-control/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,10 @@ export const borderControlPopoverControls = css`
export const borderControlPopoverContent = css``;
export const borderColorIndicator = css``;

export const resetButton = css`
justify-content: center;
width: 100%;

/* Override button component styling */
&& {
border-top: ${ CONFIG.borderWidth } solid ${ COLORS.gray[ 400 ] };
border-top-left-radius: 0;
border-top-right-radius: 0;
}
export const clearButton = css`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reference

.components-circular-option-picker__custom-clear-wrapper {
display: flex;
justify-content: flex-end;
margin-top: $grid-unit-15;
}

display: flex;
justify-content: flex-end;
margin-top: 12px;
`;

export const borderSlider = () => css`
Expand Down
8 changes: 4 additions & 4 deletions packages/components/src/border-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ describe( 'BorderControl', () => {
const solidButton = getButton( 'Solid' );
const dashedButton = getButton( 'Dashed' );
const dottedButton = getButton( 'Dotted' );
const resetButton = getButton( 'Reset' );
const clearButton = getButton( 'Clear' );

expect( customColorPicker ).toBeInTheDocument();
expect( colorSwatchButtons.length ).toEqual( colors.length );
expect( styleLabel ).toBeInTheDocument();
expect( solidButton ).toBeInTheDocument();
expect( dashedButton ).toBeInTheDocument();
expect( dottedButton ).toBeInTheDocument();
expect( resetButton ).toBeInTheDocument();
expect( clearButton ).toBeInTheDocument();
} );

it( 'should not render style options when opted out of', async () => {
Expand Down Expand Up @@ -350,12 +350,12 @@ describe( 'BorderControl', () => {
expect( props.onChange ).not.toHaveBeenCalled();
} );

it( 'should reset color and style only when popover reset button clicked', async () => {
it( 'should clear color and style only when popover clear button clicked', async () => {
const user = userEvent.setup();
const props = createProps();
render( <BorderControl { ...props } /> );
await openPopover( user );
await user.click( getButton( 'Reset' ) );
await user.click( getButton( 'Clear' ) );

expect( props.onChange ).toHaveBeenNthCalledWith( 1, {
color: undefined,
Expand Down
Loading