Skip to content

Don't render swatches in color picker for empty array #1116

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bjarnef
Copy link
Contributor

@bjarnef bjarnef commented May 29, 2025

Description

Fixes #1080

It doesn't render swatches in color picker for an empty array - just like in swatches itself.

I also added a story for transparent swatches using some or the original colors here:
https://github.com/umbraco/Umbraco.UI/pull/280/files#diff-57d087d5d487ba9b3141bc5c09bd619b383d6b16b09f8e422de98852789db332R25-R42
And some point the swatches in story were limited to 3 colors, but I think it would be better to have more as originally added here https://github.com/umbraco/Umbraco.UI/pull/280/files#diff-57d087d5d487ba9b3141bc5c09bd619b383d6b16b09f8e422de98852789db332R6-R23 and in color picker. Then stories cover different states of components, so it may be easier to catch any (visual) bugs.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (minor updates related to the tooling or maintenance of the repository, does not impact compiled assets)

Motivation and context

How to test?

Screenshots (if appropriate)

image

Checklist

  • If my change requires a change to the documentation, I have updated the documentation in this pull request.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@Copilot Copilot AI review requested due to automatic review settings May 29, 2025 22:24
Copy link

Hi there @bjarnef, thank you for this contribution! 👍

While we wait for the team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where swatches are rendered in the color picker even when an empty array is provided. The changes ensure consistency with the swatches component by adding a check for empty arrays and updating associated story files.

  • Updated UUIColorPickerElement to return nothing when swatches is empty.
  • Added a NoSwatches story in both the color swatches and color picker story files.
  • Introduced a TransparentSwatches story in the color picker story file.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/uui-color-swatches/lib/uui-color-swatches.story.ts Added a NoSwatches story to test empty swatches behavior.
packages/uui-color-picker/lib/uui-color-picker.story.ts Added NoSwatches and TransparentSwatches stories with test data for swatches and opacity.
packages/uui-color-picker/lib/uui-color-picker.element.ts Updated _renderSwatches to return nothing if swatches array is empty.

@@ -530,7 +530,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
}

private _renderSwatches() {
if (!this.swatches) return nothing;
if (!this.swatches || this.swatches.length === 0) return nothing;
Copy link
Preview

Copilot AI May 29, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider using optional chaining for a more concise empty check, for example: 'if (!this.swatches?.length) return nothing;'.

Suggested change
if (!this.swatches || this.swatches.length === 0) return nothing;
if (!this.swatches?.length) return nothing;

Copilot uses AI. Check for mistakes.

Copy link

@bjarnef
Copy link
Contributor Author

bjarnef commented Jun 3, 2025

@iOvergaard perhaps include this in v1.14.0 release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Color Picker: Hide swatches when empty
1 participant