Repository navigation
Fix Color Picker Angle Reset on Gradient Type Change #76595
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
Merged
ciampo
merged 11 commits into
WordPress:trunk
from
Vedant-Gandhi:fix/color-picker-gradient-angle-reset
Mar 19, 2026
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e33b4ad
fix: import sequence
Vedant-Gandhi 7734644
fix: remove typefixture for AngleControl
Vedant-Gandhi d464fd1
feat: add test cases
Vedant-Gandhi 3e9a34f
doc: add public facing component to changelog instead of gradient picker
Vedant-Gandhi cb3fd26
fix: restore default linear gradient orientation as horizontal
Vedant-Gandhi 9b38d26
feat: update test case to set horizontal gradient as default
Vedant-Gandhi 052ea0a
feat: update test case default result to be more generic
Vedant-Gandhi d1d30f9
feat: improve restore test case to use a non-default value
Vedant-Gandhi 1a482bd
Merge branch 'trunk' into fix/color-picker-gradient-angle-reset
Vedant-Gandhi d502048
refactor: move changelog to unrelease section
Vedant-Gandhi 21229f0
doc: add bug fixes section in changelog
Vedant-Gandhi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/components/src/custom-gradient-picker/test/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import CustomGradientPicker from '../'; | ||
|
|
||
| describe( 'CustomGradientPicker', () => { | ||
| describe( 'GradientTypePicker angle persistence', () => { | ||
| it( 'should restore the previous linear angle when switching from radial back to linear', async () => { | ||
| const user = userEvent.setup(); | ||
| const onChange = jest.fn(); | ||
|
|
||
| render( | ||
| <CustomGradientPicker | ||
| value="linear-gradient(125deg,rgb(0,0,0) 0%,rgb(255,255,255) 100%)" | ||
| onChange={ onChange } | ||
| /> | ||
| ); | ||
|
|
||
| const typeSelect = screen.getByRole( 'combobox', { | ||
| name: /type/i, | ||
| } ); | ||
| await user.selectOptions( typeSelect, 'radial-gradient' ); | ||
| await user.selectOptions( typeSelect, 'linear-gradient' ); | ||
|
|
||
| // Verify the angle from before the radial switch is restored, not the default | ||
| const lastCall = | ||
| onChange.mock.calls[ onChange.mock.calls.length - 1 ][ 0 ]; | ||
| expect( lastCall ).toContain( '125deg' ); | ||
| } ); | ||
|
|
||
| it( 'should use HORIZONTAL_GRADIENT_ORIENTATION when no prior linear angle exists', async () => { | ||
| const user = userEvent.setup(); | ||
| const onChange = jest.fn(); | ||
|
|
||
| // Start with a radial gradient so there is no previous linear angle in the ref | ||
| render( | ||
| <CustomGradientPicker | ||
| value="radial-gradient(rgb(0,0,0) 0%, rgb(255,255,255) 100%)" | ||
| onChange={ onChange } | ||
| /> | ||
| ); | ||
|
|
||
| const typeSelect = screen.getByRole( 'combobox', { | ||
| name: /type/i, | ||
| } ); | ||
| await user.selectOptions( typeSelect, 'linear-gradient' ); | ||
|
|
||
| const lastCall = | ||
| onChange.mock.calls[ onChange.mock.calls.length - 1 ][ 0 ]; | ||
| expect( lastCall ).toContain( '90deg' ); | ||
| } ); | ||
|
|
||
| it( 'should not restore angle when switching to radial', async () => { | ||
| const user = userEvent.setup(); | ||
| const onChange = jest.fn(); | ||
|
|
||
| render( | ||
| <CustomGradientPicker | ||
| value="linear-gradient(45deg, rgb(0,0,0) 0%, rgb(255,255,255) 100%)" | ||
| onChange={ onChange } | ||
| /> | ||
| ); | ||
|
|
||
| const typeSelect = screen.getByRole( 'combobox', { | ||
| name: /type/i, | ||
| } ); | ||
| await user.selectOptions( typeSelect, 'radial-gradient' ); | ||
|
|
||
| // Radial gradients have no orientation, so deg should not appear in the output | ||
| const lastCall = | ||
| onChange.mock.calls[ onChange.mock.calls.length - 1 ][ 0 ]; | ||
| expect( lastCall ).not.toContain( 'deg' ); | ||
| } ); | ||
| } ); | ||
| } ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.