Open enkelmedia opened 4 months ago
Hi there @enkelmedia!
Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.
We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.
We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.
Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:
For now I have hacked the planet @enkelmedia and done it like so
import { css, customElement, html } from "@umbraco-cms/backoffice/external/lit";
import { UmbModalBaseElement } from "@umbraco-cms/backoffice/modal";
import { NoEscapeModalData, NoEscapeModalValue } from "./noescape.modal.token";
import { umbFocus } from "@umbraco-cms/backoffice/lit-element";
@customElement('no-escape-modal')
export class NoEscapeModalElement extends UmbModalBaseElement<NoEscapeModalData, NoEscapeModalValue>
{
connectedCallback() {
super.connectedCallback();
document.addEventListener('keydown', this.handleKeyDown);
}
disconnectedCallback() {
document.removeEventListener('keydown', this.handleKeyDown);
super.disconnectedCallback();
}
private handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
event.preventDefault();
}
};
private confirmTheThing() {
console.log('Submitting modal and confirming the thing');
this.updateValue({confimed:true});
this._submitModal();
}
render() {
return html`
<uui-dialog-layout class="uui-text" headline="There is no escape">
You can only perform one action that will dismiss this dialog, which is clicking the button below.
If you try to escape by pressing the escape key, it will not work.
<uui-button
slot="actions"
id="confirm"
color='danger'
look="primary"
label="Yes I give in"
@click=${this.confirmTheThing}
${umbFocus()}></uui-button>
</uui-dialog-layout>
`;
}
static styles = css`
uui-box {
height:100%;
}
`;
}
export default NoEscapeModalElement;
My custom modal element uses connectedCallback
& disconnectedCallback
to add an event listener for the escape key.
If its pushed when this element (our custom modal) is present on the page. Then event.preventDefault();
is used to cancel any other events that are listening for the event of the escape key being pushed.
Is it the right way, probably not ? Does it work for now, yep !
However if HQ gang could add a property to enable/disable the ESC key and the cancel
event from the underlying HTML Dialog that would be much better than what I have 🙈
Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)
v14.1.1
Bug summary
I have a modal opened where I would like to prevent the ESC-key from closing the modal - or at least show a warning before the modal is closed.
As of now I can't really find a way to do this without introducing a hack.
In my scenario I'm using a
UmbModalRouteRegistrationController
so I was thinking that maybe there could be some kind of method that would enable developers to prevent the modal from closing?Specifics
No response
Steps to reproduce
Create a modal as per example above
Expected result / actual result
No response