improve close method

This commit is contained in:
SrGooglo 2023-08-15 18:43:40 +00:00
parent 6b13136fa6
commit b5d529a374

View File

@ -132,22 +132,32 @@ export class Drawer extends React.Component {
return await this.setState({ locked: false }) return await this.setState({ locked: false })
} }
close = () => { close = async ({
if (this.state.locked) { unlock = false
return console.warn("Cannot close a locked drawer") } = {}) => {
} return new Promise(async (resolve) => {
if (unlock) {
this.toggleVisibility(false) await this.setState({ locked: false })
this.events.emit("beforeClose")
setTimeout(() => {
if (typeof this.options.onClose === "function") {
this.options.onClose()
} }
this.props.controller.close(this.props.id) if (this.state.locked && !unlock) {
}, 500) return console.warn("Cannot close a locked drawer")
}
this.toggleVisibility(false)
this.events.emit("beforeClose")
setTimeout(() => {
if (typeof this.options.onClose === "function") {
this.options.onClose()
}
this.props.controller.close(this.props.id)
resolve()
}, 500)
})
} }
sendEvent = (...context) => { sendEvent = (...context) => {