mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
Allowed dismissing portal popup with Esc for signup page
closes https://github.com/TryGhost/Team/issues/1034 - pressing esc to dismiss popup didn't work for signup page as it was focused on input field - allows esc to dismiss popup if the focused input field is empty
This commit is contained in:
parent
7293d008c4
commit
7944e4c11d
@ -58,9 +58,8 @@ class PopupContent extends React.Component {
|
||||
if (this.node && !hasMode(['preview'])) {
|
||||
this.node.focus();
|
||||
this.keyUphandler = (event) => {
|
||||
const eventTargetTag = (event.target && event.target.tagName);
|
||||
if (event.key === 'Escape' && eventTargetTag !== 'INPUT') {
|
||||
this.context.onAction('closePopup');
|
||||
if (event.key === 'Escape') {
|
||||
this.dismissPopup(event);
|
||||
}
|
||||
};
|
||||
this.node.ownerDocument.removeEventListener('keyup', this.keyUphandler);
|
||||
@ -69,6 +68,15 @@ class PopupContent extends React.Component {
|
||||
this.sendContainerHeightChangeEvent();
|
||||
}
|
||||
|
||||
dismissPopup(event) {
|
||||
const eventTargetTag = (event.target && event.target.tagName);
|
||||
// If focused on input field, only allow close if no value entered
|
||||
const allowClose = eventTargetTag !== 'INPUT' || (eventTargetTag === 'INPUT' && !event?.target?.value);
|
||||
if (allowClose) {
|
||||
this.context.onAction('closePopup');
|
||||
}
|
||||
}
|
||||
|
||||
sendContainerHeightChangeEvent() {
|
||||
if (this.node && hasMode(['preview'])) {
|
||||
if (this.node?.clientHeight !== this.lastContainerHeight) {
|
||||
|
Loading…
Reference in New Issue
Block a user