Skip to content

Commit 8601f90

Browse files
author
JelteMX
committed
Add option to not render the menu content when closed
1 parent afe5a6c commit 8601f90

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dropdowncontainer",
33
"widgetName": "DropdownContainer",
4-
"version": "1.1.0",
4+
"version": "1.2.0",
55
"description": "Place Mendix components in a dropdown",
66
"copyright": "Mendix 2019",
77
"author": "Jelte Lagendijk <jelte.lagendijk@mendix.com>",

src/DropdownContainer.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
<caption>Menu self-close</caption>
3333
<description>If set to true: clicking on the menu or it's buttons will close the dropdown menu.</description>
3434
</property>
35+
<property key="renderMenuContentWhenClosed" type="boolean" defaultValue="true">
36+
<caption>Render closed content</caption>
37+
<description>This can be set to false if you happen to have a lot of content to be rendered. This could impact the performance of your page. Only disable when having performance issues.</description>
38+
</property>
3539
</propertyGroup>
3640
<propertyGroup caption="Elements">
3741
<property key="content" type="widgets" required="false">

src/components/DropDown.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface DropDownProps {
1818
isRightAligned: boolean;
1919
startOpen: boolean;
2020
autoClose: boolean;
21+
renderClosed: boolean;
2122
content?: ReactNode;
2223
buttonSize: AppearanceButtonSizeEnum;
2324
buttonType: AppearanceButtonTypeEnum;
@@ -117,14 +118,15 @@ export class DropDownInternal extends Component<DropDownProps, DropDownState> {
117118
}
118119

119120
private renderMenu(): ReactNode {
120-
const { content, isRightAligned } = this.props;
121+
const { content, isRightAligned, renderClosed } = this.props;
122+
const { open } = this.state;
121123

122124
return (
123125
<div
124126
className={classNames("dropdown-menu", { "dropdown-menu-right": isRightAligned })}
125127
onClick={this.handleMenuClick}
126128
>
127-
{content}
129+
{!open && !renderClosed ? null : content}
128130
</div>
129131
);
130132
}
@@ -209,31 +211,33 @@ export class DropDownInternal extends Component<DropDownProps, DropDownState> {
209211
export const DropDown = onClickOutside(DropDownInternal);
210212

211213
export const getFilteredProps = (
212-
props: DropdownContainerContainerProps | DropdownContainerPreviewProps,
213-
isWebModeler = false
214-
): DropDownProps => {
215-
const {
214+
{
215+
renderMenuContentWhenClosed,
216216
generalButtonGlyphicon,
217217
generalIsDropUp,
218218
generalIsRightAligned,
219219
generalStartOpen,
220220
generalAutoClose,
221221
content,
222+
class: className,
222223
appearanceButtonSize,
223224
appearanceButtonType,
224225
splitButtonSplitButtonActive
225-
} = props;
226+
}: DropdownContainerContainerProps | DropdownContainerPreviewProps,
227+
isWebModeler = false
228+
): DropDownProps => {
226229
const returnProps: DropDownProps = {
227230
glyphicon: generalButtonGlyphicon,
228231
isDropUp: generalIsDropUp,
229232
isRightAligned: generalIsRightAligned,
230233
startOpen: generalStartOpen,
231234
autoClose: generalAutoClose,
235+
renderClosed: renderMenuContentWhenClosed,
232236
content,
233237
buttonSize: appearanceButtonSize,
234238
buttonType: appearanceButtonType,
235239
splitButtonActive: splitButtonSplitButtonActive,
236-
extraClasses: props.class,
240+
extraClasses: className,
237241
isWebModeler
238242
};
239243
return returnProps;

src/components/__tests__/DropDown.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { DropDown, DropDownProps } from "../DropDown";
66
describe("DropDown", () => {
77
it("should render the structure correctly", () => {
88
const props: DropDownProps = {
9+
renderClosed: true,
910
isDropUp: true,
1011
isRightAligned: true,
1112
extraClasses: "",

src/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="DropdownContainer" version="1.1.0" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="DropdownContainer" version="1.2.0" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="DropdownContainer.xml"/>
66
</widgetFiles>

typings/DropdownContainerProps.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface DropdownContainerContainerProps extends CommonProps {
2626
generalIsRightAligned: boolean;
2727
generalStartOpen: boolean;
2828
generalAutoClose: boolean;
29+
renderMenuContentWhenClosed: boolean;
2930
content?: ReactNode;
3031
appearanceButtonSize: AppearanceButtonSizeEnum;
3132
appearanceButtonType: AppearanceButtonTypeEnum;
@@ -43,6 +44,7 @@ export interface DropdownContainerPreviewProps {
4344
generalIsRightAligned: boolean;
4445
generalStartOpen: boolean;
4546
generalAutoClose: boolean;
47+
renderMenuContentWhenClosed: boolean;
4648
content?: ReactNode;
4749
appearanceButtonSize: AppearanceButtonSizeEnum;
4850
appearanceButtonType: AppearanceButtonTypeEnum;
@@ -57,6 +59,7 @@ export interface VisibilityMap {
5759
generalIsRightAligned: boolean;
5860
generalStartOpen: boolean;
5961
generalAutoClose: boolean;
62+
renderMenuContentWhenClosed: boolean;
6063
content: boolean;
6164
appearanceButtonSize: boolean;
6265
appearanceButtonType: boolean;

0 commit comments

Comments
 (0)