fix:allow clear button in tree select widget (#16542)

* Fix: tree select allowClear button

* fix: import duplication

* Fix: add tests for bug

* fix: Add Placeholder fix

* fix: test case

* fix: remove comments
This commit is contained in:
Tolulope Adetula 2022-09-09 12:55:31 +01:00 committed by GitHub
parent 5642274694
commit b4b4284a56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 4 deletions

View File

@ -111,6 +111,28 @@ describe("Single Select Widget Functionality", function() {
"No Results Found",
);
});
it("8. To Check Clear all functionality", function() {
cy.openPropertyPane("textwidget");
cy.updateCodeInput(
".t--property-control-text",
`{{SingleSelectTree1.selectedOptionValue}}`,
);
cy.openPropertyPane("singleselecttreewidget");
cy.togglebar(
'.t--property-control-allowclearingvalue input[type="checkbox"]',
);
cy.get(formWidgetsPage.treeSelectClearAll)
.last()
.click({ force: true });
cy.wait(100);
cy.get(".t--widget-textwidget").should("contain", "");
cy.get(formWidgetsPage.treeSelectClearAll).should("not.exist");
cy.get(formWidgetsPage.treeSelectPlaceholder).should(
"contain",
"select option",
);
});
});
afterEach(() => {
// put your clean up code if any

View File

@ -30,6 +30,8 @@
"dropdownInput": ".bp3-tag-input-values",
"mulitiselectInput": ".rc-select-selection-search-input",
"treeSelectInput": ".rc-tree-select-selection-search-input",
"treeSelectClearAll":".rc-tree-select-clear",
"treeSelectPlaceholder":".rc-tree-select-single .rc-tree-select-selection-placeholder",
"treeSelectFilterInput": ".tree-select-dropdown .bp3-input",
"multiTreeSelectFilterInput": ".tree-multiselect-dropdown .bp3-input",
"labelradio": ".t--draggable-radiogroupwidget label",

View File

@ -22,11 +22,11 @@ import styled from "styled-components";
import { RenderMode, TextSize } from "constants/WidgetConstants";
import { Alignment, Button, Classes, InputGroup } from "@blueprintjs/core";
import { labelMargin, WidgetContainerDiff } from "widgets/WidgetUtils";
import { Icon } from "design-system";
import { Icon, LabelWithTooltip } from "design-system";
import { Colors } from "constants/Colors";
import { LabelPosition } from "components/constants";
import { LabelWithTooltip } from "design-system";
import useDropdown from "widgets/useDropdown";
import { isNil } from "lodash";
export interface TreeSelectProps
extends Required<
@ -220,6 +220,12 @@ function SingleSelectTreeComponent({
// Clear the search input on closing the widget
setFilter("");
};
const allowClearMemo = useMemo(
() => allowClear && !isNil(value) && value !== "",
[allowClear, value],
);
const memoValue = useMemo(() => (value !== "" ? value : undefined), [value]);
return (
<TreeSelectContainer
@ -257,7 +263,7 @@ function SingleSelectTreeComponent({
)}
<InputContainer compactMode={compactMode} labelPosition={labelPosition}>
<TreeSelect
allowClear={allowClear}
allowClear={allowClearMemo}
animation="slide-up"
choiceTransitionName="rc-tree-select-selection__choice-zoom"
className="rc-tree-select"
@ -304,7 +310,7 @@ function SingleSelectTreeComponent({
treeDefaultExpandAll={expandAll}
treeIcon
treeNodeFilterProp="label"
value={filter ? "" : value} // value should empty when filter value exist otherwise dropdown flickers #12714
value={memoValue}
/>
</InputContainer>
</TreeSelectContainer>