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

[FIX] ColorPicker: conditionally hide reset button #5025

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
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
1 change: 1 addition & 0 deletions src/components/color_picker/color_picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export interface ColorPickerProps {
dropdownDirection?: "left" | "right" | "center";
onColorPicked: (color: Color) => void;
currentColor: Color;
disableNoColor?: boolean;
}

interface State {
Expand Down
10 changes: 6 additions & 4 deletions src/components/color_picker/color_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@
<button class="o-add-button" t-on-click="setCustomColor">Add</button>
</div>
</div>
<div class="o-separator"/>
<div class="o-buttons">
<button t-on-click="resetColor" class="o-cancel">Reset</button>
</div>
<t t-if="!props.disableNoColor">
<div class="o-separator"/>
<div class="o-buttons">
<button t-on-click="resetColor" class="o-cancel">Reset</button>
</div>
</t>
</div>
</t>
</templates>
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
dropdownDirection="'left'"
onColorPicked="(color) => this.setColorScaleColor(thresholdType, color)"
currentColor="getThresholdColor(threshold)"
disableNoColor="true"
/>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions tests/components/color_picker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async function mountColorPicker(partialProps: Partial<ColorPickerProps> = {}, mo
onColorPicked: partialProps.onColorPicked || (() => {}),
currentColor: partialProps.currentColor || "#000000",
maxHeight: partialProps.maxHeight !== undefined ? partialProps.maxHeight : 1000,
disableNoColor: partialProps.disableNoColor || false,
};
({ fixture } = await mountComponent(ColorPicker, { model, props }));
}
Expand Down Expand Up @@ -165,4 +166,9 @@ describe("Color Picker buttons", () => {
const picker = fixture.querySelector<HTMLElement>(".o-color-picker")!;
expect(picker.style["display"]).toEqual("none");
});

test("Hides the 'No Color' button when disableNoColor prop is set to true", async () => {
await mountColorPicker({ disableNoColor: true });
expect(fixture.querySelector(".o-buttons .o-cancel")).toBeNull();
});
});
12 changes: 12 additions & 0 deletions tests/components/conditional_formatting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,18 @@ describe("UI of conditional formats", () => {
expect(errorMessages()).toEqual(["Invalid Maxpoint formula"]);
});

test("Hides the 'No Color' button when the color picker is opened for the color scale", async () => {
triggerMouseEvent(selectors.buttonAdd, "click");
await nextTick();

triggerMouseEvent(document.querySelectorAll(selectors.cfTabSelector)[1], "click");
await nextTick();

triggerMouseEvent(selectors.colorScaleEditor.minColor, "click");
await nextTick();
expect(fixture.querySelector(".o-buttons .o-cancel")).toBeNull();
});

describe("Icon set CF", () => {
test("can select the Icon set tab", async () => {
triggerMouseEvent(selectors.buttonAdd, "click");
Expand Down