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: Popover in Multi select widget inside modals breaks away from the widget #13129

Merged
merged 36 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9301bf9
fix: Popover in Multi select widget inside modals breaks away from th…
wmdev0808 Apr 20, 2022
43ca423
Merge branch 'release' into fix/12161-multiselects-broken-in-modal
wmdev0808 Apr 20, 2022
b2c1ebf
fix: Popover in Multi select widget inside modals breaks away from th…
wmdev0808 Apr 20, 2022
ef56d73
Merge branch 'release' into fix/12161-multiselects-broken-in-modal
wmdev0808 Apr 20, 2022
0771f23
fix: Popover in Multi select widget inside modals breaks away from th…
wmdev0808 Apr 20, 2022
58dfb48
Merge branch 'release' into fix/12161-multiselects-broken-in-modal
wmdev0808 May 4, 2022
806b212
Merge branch 'release' into fix/12161-multiselects-broken-in-modal
Tooluloope May 24, 2022
9a8bb35
fix: popup issues
Tooluloope May 24, 2022
2d694ca
remove unused code
Tooluloope May 24, 2022
d07d8f8
fix: PR review
Tooluloope May 25, 2022
17ec737
Revert "fix: popup issues"
Tooluloope May 30, 2022
88a1daa
Revert "remove unused code"
Tooluloope May 30, 2022
e1301dc
fix: remove autofocus
Tooluloope May 31, 2022
af17e7b
Merge branch 'release' into fix/12161-multiselects-broken-in-modal
Tooluloope May 31, 2022
b22975f
fix: PR review
Tooluloope May 31, 2022
6108d6f
Fix: Disable scrolling when dropdown opens
Tooluloope Jun 1, 2022
1680df9
fix: for MultiSelect
Tooluloope Jun 8, 2022
0d4f8a0
Merge branch 'release' into fix/12161-multiselects-broken-in-modal
Tooluloope Jun 8, 2022
22db2ed
fix: TreeSelect
Tooluloope Jun 8, 2022
3a33155
fix: remove dead code
Tooluloope Jun 8, 2022
665aec5
Merge branch 'release' into fix/12161-multiselects-broken-in-modal
Tooluloope Jun 8, 2022
cef5bed
fix: empty commit
Tooluloope Jun 9, 2022
4d5fc3b
Revert "fix: empty commit"
Tooluloope Jun 9, 2022
bd4632a
fix: refactor code
Tooluloope Jun 9, 2022
b77870a
Merge branch 'release' into fix/12161-multiselects-broken-in-modal
Tooluloope Jun 9, 2022
1f0c38b
fix: remove template literals
Tooluloope Jun 9, 2022
2c46d42
fix: CANVAS_SELECTOR
Tooluloope Jun 9, 2022
909bbf0
fix: remove console statements
Tooluloope Jun 9, 2022
3d7d891
fix: more refactoring
Tooluloope Jun 9, 2022
ddaf283
fix: add code comments
Tooluloope Jun 9, 2022
90532f1
merged latest release
ashit-rath Jun 17, 2022
2c6054f
Merge branch 'release' into fix/12161-multiselects-broken-in-modal
Tooluloope Jun 20, 2022
7ab05c4
fix: failing tests
Tooluloope Jun 20, 2022
5af2839
fix: popup issue
Tooluloope Jun 21, 2022
31f91f6
fix: use ESC to close dropdown
Tooluloope Jun 22, 2022
43ecd36
fix: failing tests
Tooluloope Jun 22, 2022
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 app/client/src/constants/WidgetConstants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const MAIN_CONTAINER_WIDGET_ID = "0";
export const MAIN_CONTAINER_WIDGET_NAME = "MainContainer";
export const MODAL_PORTAL_CLASSNAME = "bp3-modal-widget";
export const CANVAS_CLASSNAME = "appsmith_widget_0";
export const CANVAS_SELECTOR = `[type="CANVAS_WIDGET"]`;

export const DEFAULT_CENTER = { lat: -34.397, lng: 150.644 };

Expand Down
23 changes: 9 additions & 14 deletions app/client/src/widgets/MultiSelectTreeWidget/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import "rc-tree-select/assets/index.less";
import { DefaultValueType } from "rc-tree-select/lib/interface";
import { TreeNodeProps } from "rc-tree-select/lib/TreeNode";
import { CheckedStrategy } from "rc-tree-select/lib/utils/strategyUtil";
import {
CANVAS_CLASSNAME,
MODAL_PORTAL_CLASSNAME,
TextSize,
} from "constants/WidgetConstants";
import { TextSize } from "constants/WidgetConstants";
import { Alignment, Button, Classes, InputGroup } from "@blueprintjs/core";
import { labelMargin, WidgetContainerDiff } from "widgets/WidgetUtils";
import {
getClosestCanvas,
labelMargin,
WidgetContainerDiff,
} from "widgets/WidgetUtils";
import Icon from "components/ads/Icon";
import { Colors } from "constants/Colors";
import { LabelPosition } from "components/constants";
Expand Down Expand Up @@ -146,14 +146,9 @@ function MultiTreeSelectComponent({
[filter],
);

const getDropdownPosition = useCallback(() => {
const getPopupContainer = useCallback(() => {
const node = _menu.current;
if (Boolean(node?.closest(`.${MODAL_PORTAL_CLASSNAME}`))) {
return document.querySelector(
`.${MODAL_PORTAL_CLASSNAME}`,
) as HTMLElement;
}
return document.querySelector(`.${CANVAS_CLASSNAME}`) as HTMLElement;
return getClosestCanvas(node);
}, []);
const onQueryChange = useCallback((event: ChangeEvent<HTMLInputElement>) => {
event.stopPropagation();
Expand Down Expand Up @@ -251,7 +246,7 @@ function MultiTreeSelectComponent({
dropdownRender={dropdownRender}
dropdownStyle={dropdownStyle}
filterTreeNode
getPopupContainer={getDropdownPosition}
getPopupContainer={getPopupContainer}
inputIcon={
<Icon
className="dropdown-icon"
Expand Down
19 changes: 5 additions & 14 deletions app/client/src/widgets/MultiSelectWidget/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ import {
MultiSelectContainer,
StyledCheckbox,
} from "./index.styled";
import {
CANVAS_CLASSNAME,
MODAL_PORTAL_CLASSNAME,
TextSize,
} from "constants/WidgetConstants";
import { TextSize } from "constants/WidgetConstants";
import debounce from "lodash/debounce";
import Icon from "components/ads/Icon";
import { Alignment, Classes } from "@blueprintjs/core";
import { WidgetContainerDiff } from "widgets/WidgetUtils";
import { getClosestCanvas, WidgetContainerDiff } from "widgets/WidgetUtils";
import _ from "lodash";
import { Colors } from "constants/Colors";
import { LabelPosition } from "components/constants";
Expand Down Expand Up @@ -99,14 +95,9 @@ function MultiSelectComponent({
}
}, [options, value]);

const getDropdownPosition = useCallback(() => {
const getPopupContainer = useCallback(() => {
const node = _menu.current;
if (Boolean(node?.closest(`.${MODAL_PORTAL_CLASSNAME}`))) {
return document.querySelector(
`.${MODAL_PORTAL_CLASSNAME}`,
) as HTMLElement;
}
return document.querySelector(`.${CANVAS_CLASSNAME}`) as HTMLElement;
return getClosestCanvas(node);
}, []);

const handleSelectAll = () => {
Expand Down Expand Up @@ -202,7 +193,7 @@ function MultiSelectComponent({
dropdownRender={dropdownRender}
dropdownStyle={dropdownStyle}
filterOption={serverSideFiltering ? false : filterOption}
getPopupContainer={getDropdownPosition}
getPopupContainer={getPopupContainer}
inputIcon={
<Icon
className="dropdown-icon"
Expand Down
23 changes: 9 additions & 14 deletions app/client/src/widgets/MultiSelectWidgetV2/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import MenuItemCheckBox, {
StyledCheckbox,
InputContainer,
} from "./index.styled";
import {
CANVAS_CLASSNAME,
MODAL_PORTAL_CLASSNAME,
TextSize,
} from "constants/WidgetConstants";
import { TextSize } from "constants/WidgetConstants";
import Icon from "components/ads/Icon";
import { Alignment, Button, Classes, InputGroup } from "@blueprintjs/core";
import { labelMargin, WidgetContainerDiff } from "widgets/WidgetUtils";
import {
getClosestCanvas,
labelMargin,
WidgetContainerDiff,
} from "widgets/WidgetUtils";
import { Colors } from "constants/Colors";
import { LabelPosition } from "components/constants";
import { uniqBy } from "lodash";
Expand Down Expand Up @@ -157,14 +157,9 @@ function MultiSelectComponent({
) : null,
[filter],
);
const getDropdownPosition = useCallback(() => {
const getPopupContainer = useCallback(() => {
const node = _menu.current;
if (Boolean(node?.closest(`.${MODAL_PORTAL_CLASSNAME}`))) {
return document.querySelector(
`.${MODAL_PORTAL_CLASSNAME}`,
) as HTMLElement;
}
return document.querySelector(`.${CANVAS_CLASSNAME}`) as HTMLElement;
return getClosestCanvas(node);
}, []);

const handleSelectAll = () => {
Expand Down Expand Up @@ -347,7 +342,7 @@ function MultiSelectComponent({
dropdownClassName={`multi-select-dropdown multiselect-popover-width-${widgetId}`}
dropdownRender={dropdownRender}
dropdownStyle={dropdownStyle}
getPopupContainer={getDropdownPosition}
getPopupContainer={getPopupContainer}
inputIcon={
<Icon
className="dropdown-icon"
Expand Down
23 changes: 9 additions & 14 deletions app/client/src/widgets/SingleSelectTreeWidget/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import {
import "rc-tree-select/assets/index.less";
import { DefaultValueType } from "rc-tree-select/lib/interface";
import { TreeNodeProps } from "rc-tree-select/lib/TreeNode";
import {
CANVAS_CLASSNAME,
MODAL_PORTAL_CLASSNAME,
TextSize,
} from "constants/WidgetConstants";
import { TextSize } from "constants/WidgetConstants";
import { Alignment, Button, Classes, InputGroup } from "@blueprintjs/core";
import { labelMargin, WidgetContainerDiff } from "widgets/WidgetUtils";
import {
getClosestCanvas,
labelMargin,
WidgetContainerDiff,
} from "widgets/WidgetUtils";
import Icon from "components/ads/Icon";
import { Colors } from "constants/Colors";
import { LabelPosition } from "components/constants";
Expand Down Expand Up @@ -135,14 +135,9 @@ function SingleSelectTreeComponent({
setKey(Math.random());
}, [expandAll]);

const getDropdownPosition = useCallback(() => {
const getPopupContainer = useCallback(() => {
const node = _menu.current;
if (Boolean(node?.closest(`.${MODAL_PORTAL_CLASSNAME}`))) {
return document.querySelector(
`.${MODAL_PORTAL_CLASSNAME}`,
) as HTMLElement;
}
return document.querySelector(`.${CANVAS_CLASSNAME}`) as HTMLElement;
return getClosestCanvas(node);
}, []);
const onClear = useCallback(() => onChange([], []), []);
const onOpen = useCallback((open: boolean) => {
Expand Down Expand Up @@ -245,7 +240,7 @@ function SingleSelectTreeComponent({
dropdownRender={dropdownRender}
dropdownStyle={dropdownStyle}
filterTreeNode
getPopupContainer={getDropdownPosition}
getPopupContainer={getPopupContainer}
inputIcon={
<Icon
className="dropdown-icon"
Expand Down
5 changes: 5 additions & 0 deletions app/client/src/widgets/WidgetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { Alignment } from "@blueprintjs/core";
import { IconName } from "@blueprintjs/icons";
import {
CANVAS_SELECTOR,
CONTAINER_GRID_PADDING,
GridDefaults,
WIDGET_PADDING,
Expand Down Expand Up @@ -254,3 +255,7 @@ export const sanitizeKey = (key: string, options?: SanitizeOptions) => {

return sanitizedKey;
};

export const getClosestCanvas = (node: HTMLElement | null) => {
return node?.closest(`${CANVAS_SELECTOR}`) as HTMLElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: node?.closest(CANVAS_SELECTOR)

};