Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
31 changes: 31 additions & 0 deletions packages/main/cypress/specs/ColorPalette.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,34 @@ describe("Color Palette - getFocusDomRef", () => {
});
});
});

describe("Color Palette Item - tooltip", () => {
it("should display the color value as tooltip when no custom tooltip is set", () => {
cy.mount(
<ColorPalette>
<ColorPaletteItem id="no-tooltip" value="darkblue"></ColorPaletteItem>
</ColorPalette>
);

cy.get("#no-tooltip")
.shadow()
.find(".ui5-cp-item")
.should("have.attr", "title")
.and("contain", "darkblue");
});

it("should display the custom tooltip when tooltip property is set", () => {
cy.mount(
<ColorPalette>
<ColorPaletteItem id="custom-tooltip" value="#d60d5a" tooltip="Raspberry"></ColorPaletteItem>
</ColorPalette>
);

cy.get("#custom-tooltip")
.shadow()
.find(".ui5-cp-item")
.should("have.attr", "title")
.and("contain", "Raspberry")
.and("not.contain", "#d60d5a");
});
});
13 changes: 13 additions & 0 deletions packages/main/src/ColorPaletteItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ class ColorPaletteItem extends UI5Element implements IColorPaletteItem {
@property({ type: Boolean })
selected = false;

/**
* Defines the tooltip of the component. When not set, the color value is used as the tooltip.
*
* @public
* @since 2.22.0
*/
@property()
tooltip?: string;

/**
* Defines the tab-index of the element, helper information for the ItemNavigation.
* @private
Expand Down Expand Up @@ -107,6 +116,10 @@ class ColorPaletteItem extends UI5Element implements IColorPaletteItem {
return ColorPaletteItem.i18nBundle.getText(COLORPALETTE_COLOR_LABEL);
}

get getLabelText(): string {
return `${this.colorLabel} - ${this.index}: ${this.tooltip || this.value}`;
}

get classes() {
// Remove after deleting the hbs template, it's added in the jsx template
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/ColorPaletteItemTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export default function ColorPaletteItemTemplate(this: ColorPaletteItem) {
class="ui5-cp-item"
tabindex={parseInt(this.forcedTabIndex)}
role="button"
aria-label={`${this.colorLabel} - ${this.index}: ${this.value}`}
aria-label={this.getLabelText}
aria-pressed={this.selected}
title={`${this.colorLabel} - ${this.index}: ${this.value}`}
title={this.getLabelText}
></div>
);
}
6 changes: 3 additions & 3 deletions packages/main/test/pages/ColorPalette.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
<ui5-color-palette id="cp1SelectedTest">
<ui5-color-palette-item value="darkblue" selected></ui5-color-palette-item>
<ui5-color-palette-item value="pink" selected></ui5-color-palette-item>
<ui5-color-palette-item value="#444444" selected></ui5-color-palette-item>
<ui5-color-palette-item value="rgb(0,200,0)" selected></ui5-color-palette-item>
<ui5-color-palette-item value="#444444" tooltip="charcoal" selected></ui5-color-palette-item>
<ui5-color-palette-item value="rgb(0,200,0)" tooltip="lime green" selected></ui5-color-palette-item>
<ui5-color-palette-item value="green"></ui5-color-palette-item>
<ui5-color-palette-item value="darkred"></ui5-color-palette-item>
<ui5-color-palette-item value="yellow"></ui5-color-palette-item>
<ui5-color-palette-item value="blue"></ui5-color-palette-item>
<ui5-color-palette-item value="cyan"></ui5-color-palette-item>
<ui5-color-palette-item value="orange"></ui5-color-palette-item>
<ui5-color-palette-item value="#5480e7"></ui5-color-palette-item>
<ui5-color-palette-item value="#ff6699"></ui5-color-palette-item>
<ui5-color-palette-item value="#ff6699" tooltip="brilliant rose"></ui5-color-palette-item>
</ui5-color-palette>
<br/>
<br/>
Expand Down
Loading