Skip to content
Open
Show file tree
Hide file tree
Changes from all 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");
});
});
16 changes: 15 additions & 1 deletion packages/main/src/ColorPaletteItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,23 @@ class ColorPaletteItem extends UI5Element implements IColorPaletteItem {
* **Note:** Only one item must be selected per <code>ui5-color-palette</code>.
* If more than one item is defined as selected, the last one would be considered as the selected one.
*
* @public
* @default false
* @public
* @since 2.0.0
*/
@property({ type: Boolean })
selected = false;

/**
* Defines the tooltip of the component. When not set, the color value is used as the tooltip.
*
* @default undefined
* @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 +117,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="bright 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
<ui5-color-palette>
<ui5-color-palette-item value="darkblue"></ui5-color-palette-item>
<ui5-color-palette-item value="pink"></ui5-color-palette-item>
<ui5-color-palette-item value="#444444"></ui5-color-palette-item>
<ui5-color-palette-item value="rgb(0,200,0)"></ui5-color-palette-item>
<ui5-color-palette-item value="#444444" tooltip="charcoal"></ui5-color-palette-item>
<ui5-color-palette-item value="rgb(0,200,0)" tooltip="bright green"></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="#5480e7" tooltip="periwinkle"></ui5-color-palette-item>
<ui5-color-palette-item value="#ff6699" tooltip="brilliant rose"></ui5-color-palette-item>
</ui5-color-palette>
<!-- playground-fold -->
<script type="module" src="main.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ function App() {
<ColorPalette>
<ColorPaletteItem value="darkblue" />
<ColorPaletteItem value="pink" />
<ColorPaletteItem value="#444444" />
<ColorPaletteItem value="rgb(0,200,0)" />
<ColorPaletteItem value="#444444" tooltip="charcoal" />
<ColorPaletteItem value="rgb(0,200,0)" tooltip="bright green" />
<ColorPaletteItem value="green" />
<ColorPaletteItem value="darkred" />
<ColorPaletteItem value="yellow" />
<ColorPaletteItem value="blue" />
<ColorPaletteItem value="cyan" />
<ColorPaletteItem value="orange" />
<ColorPaletteItem value="#5480e7" />
<ColorPaletteItem value="#ff6699" />
<ColorPaletteItem value="#5480e7" tooltip="periwinkle" />
<ColorPaletteItem value="#ff6699" tooltip="brilliant rose" />
</ColorPalette>
</>
);
Expand Down
Loading