Merge pull request #4834 from appsmithorg/feature/modal-onClose
added onclose property and handlers on ModalWidget
This commit is contained in:
commit
d37c7a97a4
|
|
@ -56,6 +56,7 @@ const Content = styled.div<{
|
||||||
export type ModalComponentProps = {
|
export type ModalComponentProps = {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
onClose: (e: any) => void;
|
onClose: (e: any) => void;
|
||||||
|
onModalClose?: () => void;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
width?: number;
|
width?: number;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
|
@ -76,6 +77,14 @@ export function ModalComponent(props: ModalComponentProps) {
|
||||||
const modalContentRef: RefObject<HTMLDivElement> = useRef<HTMLDivElement>(
|
const modalContentRef: RefObject<HTMLDivElement> = useRef<HTMLDivElement>(
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
// handle modal close events when this component unmounts
|
||||||
|
// will be called in all cases :-
|
||||||
|
// escape key press, click out side, close click from other btn widget
|
||||||
|
if (props.onModalClose) props.onModalClose();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!props.scrollContents) {
|
if (!props.scrollContents) {
|
||||||
modalContentRef.current?.scrollTo({ top: 0, behavior: "smooth" });
|
modalContentRef.current?.scrollTo({ top: 0, behavior: "smooth" });
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ export enum EventType {
|
||||||
ON_HOVER = "ON_HOVER",
|
ON_HOVER = "ON_HOVER",
|
||||||
ON_TOGGLE = "ON_TOGGLE",
|
ON_TOGGLE = "ON_TOGGLE",
|
||||||
ON_LOAD = "ON_LOAD",
|
ON_LOAD = "ON_LOAD",
|
||||||
|
ON_MODAL_CLOSE = "ON_MODAL_CLOSE",
|
||||||
ON_TEXT_CHANGE = "ON_TEXT_CHANGE",
|
ON_TEXT_CHANGE = "ON_TEXT_CHANGE",
|
||||||
ON_SUBMIT = "ON_SUBMIT",
|
ON_SUBMIT = "ON_SUBMIT",
|
||||||
ON_CHECK_CHANGE = "ON_CHECK_CHANGE",
|
ON_CHECK_CHANGE = "ON_CHECK_CHANGE",
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import React, { ReactNode } from "react";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { ReduxActionTypes } from "constants/ReduxActionConstants";
|
import { ReduxActionTypes } from "constants/ReduxActionConstants";
|
||||||
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
|
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
|
||||||
|
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
|
||||||
import WidgetFactory from "utils/WidgetFactory";
|
import WidgetFactory from "utils/WidgetFactory";
|
||||||
import ModalComponent from "components/designSystems/blueprint/ModalComponent";
|
import ModalComponent from "components/designSystems/blueprint/ModalComponent";
|
||||||
import {
|
import {
|
||||||
|
|
@ -70,6 +71,20 @@ export class ModalWidget extends BaseWidget<ModalWidgetProps, WidgetState> {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
sectionName: "Actions",
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
helpText: "Triggers an action when the modal is closed",
|
||||||
|
propertyName: "onClose",
|
||||||
|
label: "onClose",
|
||||||
|
controlType: "ACTION_SELECTOR",
|
||||||
|
isJSConvertible: true,
|
||||||
|
isBindProperty: true,
|
||||||
|
isTriggerProperty: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
|
|
@ -99,6 +114,18 @@ export class ModalWidget extends BaseWidget<ModalWidgetProps, WidgetState> {
|
||||||
return WidgetFactory.createWidget(childWidgetData, this.props.renderMode);
|
return WidgetFactory.createWidget(childWidgetData, this.props.renderMode);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onModalClose = () => {
|
||||||
|
if (this.props.onClose) {
|
||||||
|
super.executeAction({
|
||||||
|
triggerPropertyName: "onClose",
|
||||||
|
dynamicString: this.props.onClose,
|
||||||
|
event: {
|
||||||
|
type: EventType.ON_MODAL_CLOSE,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
closeModal = (e: any) => {
|
closeModal = (e: any) => {
|
||||||
this.props.showPropertyPane(undefined);
|
this.props.showPropertyPane(undefined);
|
||||||
// TODO(abhinav): Create a static property with is a map of widget properties
|
// TODO(abhinav): Create a static property with is a map of widget properties
|
||||||
|
|
@ -124,6 +151,7 @@ export class ModalWidget extends BaseWidget<ModalWidgetProps, WidgetState> {
|
||||||
height={MODAL_SIZE[this.props.size].height}
|
height={MODAL_SIZE[this.props.size].height}
|
||||||
isOpen={!!this.props.isVisible}
|
isOpen={!!this.props.isVisible}
|
||||||
onClose={this.closeModal}
|
onClose={this.closeModal}
|
||||||
|
onModalClose={this.onModalClose}
|
||||||
scrollContents={!!this.props.shouldScrollContents}
|
scrollContents={!!this.props.shouldScrollContents}
|
||||||
width={this.getModalWidth()}
|
width={this.getModalWidth()}
|
||||||
>
|
>
|
||||||
|
|
@ -159,6 +187,7 @@ export interface ModalWidgetProps extends WidgetProps, WithMeta {
|
||||||
canEscapeKeyClose?: boolean;
|
canEscapeKeyClose?: boolean;
|
||||||
shouldScrollContents?: boolean;
|
shouldScrollContents?: boolean;
|
||||||
size: string;
|
size: string;
|
||||||
|
onClose: string;
|
||||||
mainContainer: WidgetProps;
|
mainContainer: WidgetProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user