-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui5-dialog): fix focusing when dialog is open from OpenUI5 dialog (…
- Loading branch information
1 parent
ef06287
commit e2a19fa
Showing
3 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
type OpenUI5Popup = { | ||
setInitialZIndex: (zIndex: number) => void, | ||
getNextZIndex: () => number, | ||
prototype: { | ||
onFocusEvent: (e: FocusEvent) => void, | ||
} | ||
}; | ||
|
||
const patchFocusEvent = (Popup: OpenUI5Popup) => { | ||
const origFocusEvent = Popup.prototype.onFocusEvent; | ||
Popup.prototype.onFocusEvent = function onFocusEvent(e: FocusEvent) { | ||
const isTypeFocus = e.type === "focus" || e.type === "activate"; | ||
const target = e.target as HTMLElement; | ||
if (!isTypeFocus || !target.closest("[ui5-popover],[ui5-responsive-popover],[ui5-dialog]")) { | ||
origFocusEvent.call(this, e); | ||
} | ||
}; | ||
}; | ||
|
||
const patchPopup = (Popup: OpenUI5Popup) => { | ||
patchFocusEvent(Popup);// Popup.prototype.onFocusEvent | ||
}; | ||
|
||
export default patchPopup; | ||
export type { OpenUI5Popup }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | ||
<title>Dialog</title> | ||
<script data-ui5-config type="application/json"> | ||
{ | ||
"language": "EN" | ||
} | ||
</script> | ||
<script> | ||
// delete Document.prototype.adoptedStyleSheets | ||
</script> | ||
<script src="%VITE_BUNDLE_PATH%" type="module"></script> | ||
<script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" | ||
id="sap-ui-bootstrap" | ||
data-sap-ui-libs="sap.m" | ||
data-sap-ui-oninit="onOpenUI5Init" | ||
data-sap-ui-compatVersion="edge"></script> | ||
<script> | ||
function onOpenUI5Init() { | ||
sap.ui.require(["sap/m/Button", "sap/m/Dialog"], (Button, Dialog) => { | ||
new Button("openUI5Button", { | ||
text: "Open OpenUI5 Dialog", | ||
press: function () { | ||
new Dialog({ | ||
title: "OpenUI5 Dialog", | ||
content: [ | ||
new Button({ | ||
text: "Focus stop" | ||
}), | ||
new Button("openResPopoverButton", { | ||
text: "Open WebC Responsive Popover", | ||
press: function () { | ||
document.getElementById("respPopover").open = true; | ||
} | ||
}) | ||
], | ||
afterClose: function () { | ||
this.destroy(); | ||
} | ||
}).open(); | ||
} | ||
}).placeAt("content"); | ||
}); | ||
} | ||
|
||
function init() { | ||
document.getElementById("myButton").addEventListener("click", function() { | ||
document.getElementById("dialog1").open = true; | ||
}); | ||
|
||
document.getElementById("dialogButton").addEventListener("click", function () { | ||
sap.ui.require(["sap/m/Button", "sap/m/Dialog"], (Button, Dialog) => { | ||
new Dialog({ | ||
title: "OpenUI5 Dialog", | ||
content: [ | ||
new Button({ | ||
text: "Focus stop" | ||
}), | ||
new Button("openUI5DialogButton", { | ||
text: "Open WebC Dialog", | ||
press: function () { | ||
document.getElementById("newDialog1").open = true; | ||
} | ||
}) | ||
], | ||
afterClose: function () { | ||
this.destroy(); | ||
} | ||
}).open(); | ||
}); | ||
}); | ||
} | ||
</script> | ||
</head> | ||
<body class="sapUiBody" onload="init()"> | ||
<div id="buttonP"> | ||
<ui5-button id="myButton">Open WebC Dialog</ui5-button> | ||
</div> | ||
<ui5-dialog id="dialog1" header-text="This is an WebC Dialog 1"> | ||
<ui5-button id="dialogButton">Open UI5 dialog</ui5-button> | ||
</ui5-dialog> | ||
<ui5-dialog id="newDialog1" header-text="This is an WebC Dialog 2"> | ||
<ui5-button id="someButton">Some button</ui5-button> | ||
</ui5-dialog> | ||
<div id="content"></div> | ||
<ui5-responsive-popover id="respPopover" | ||
opener="openResPopoverButton" | ||
header-text="This is an WebC Responsive Popover"> | ||
<ui5-button>Some button</ui5-button> | ||
</ui5-responsive-popover> | ||
</body> | ||
</html> |