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

Add support for some user supplied props in ColorGradientSettingsDropdown #60487

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

permafrost06
Copy link

What?

In the ColorGradientSettingsDropdown component in @wordpress/block-editor, props onDeselect and hasValue can be supplied by the user. if they're undefined or not a function, falls back to the default behavior.

Why?

The current behavior assumes that the default color value is empty - which isn't true sometimes. This small PR solves that.

How?

It checks whether or not the props setting.onDeselect and setting.hasValue for the component ColorGradientSettingsDropdown are functions. If they are functions, then they are run respectively when a color is reset and to check if the control has a value.

Testing Instructions

  1. Import the ColorGradientSettingsDropdown component from @wordpress/block-editor package.
  2. Set it up as needed, then include test functions for properties onDeselect and hasValue in a setting object. Example:
<ColorGradientSettingsDropdown
    enableAlpha
    panelId={clientId}
    title={__("Color Settings", "plugin_textdomain")}
    popoverProps={{
        placement: "left start",
    }}
    settings={[{
        /* rest of your settings */
        onDeselect: () => {
            console.log("color deselected");
            setAttribute({ starColor: "#FFB901" });
        }
        hasValue: () => {
            if (starColor.toUpperCase() !== "#FFB901") {
                return true;
            }
            return false;
        }
    }]}
/>

Testing Instructions for Keyboard

Screenshots or screencast

props onDeselect and hasValue can be supplied by the user.
if they're undefined or not a function, falls back to the default behavior.
@permafrost06 permafrost06 requested a review from ellatrix as a code owner April 4, 2024 21:51
Copy link

github-actions bot commented Apr 4, 2024

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core.
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

Copy link

github-actions bot commented Apr 4, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: permafrost06 <[email protected]>
Co-authored-by: carolinan <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Apr 4, 2024
Copy link

github-actions bot commented Apr 4, 2024

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @permafrost06! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@carolinan
Copy link
Contributor

Hi @permafrost06
Is there an open issue related to this pull request?
Having an issue with clear descriptions of the problem and use cases helps other contributors understand the enhancement or bug, and if the pull request is the correct solution. It also helps contributors learn if it is an issue that needs to be prioritised.

https://developer.wordpress.org/block-editor/contributors/repository-management/#pull-requests

@permafrost06
Copy link
Author

@carolinan I don't think there is an open issue related to this PR. I faced this problem while developing a block and created this PR since the fix was quite simple. If you want, I can create an issue that illustrates what problem I faced or I can create a comment on the PR with more details. Please let me know which I should do. Thank you.

@carolinan
Copy link
Contributor

Yes please open an issue since it is considered the best practice.
Please expand on the use case and what the proposed changes solve.

@permafrost06
Copy link
Author

@carolinan I have opened an issue #60536 that describes the problem this PR fixes.

This PR adds support for the hasValue and onDeselect props in the component ColorGradientSettingsDropdown.
In the implementation, it's checked whether the passed hasValue and onDeselect property values are functions. If they are functions, then they are run respectively to check whether the control has a value, therefore can be reset and when a single value is reset. If, however, the passed values are not functions, or they're not passed (i.e. they're undefined), the old behaviour is used where the attribute is set to undefined on resetting the value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants