Skip to content

Commit

Permalink
fix(csp): Make setCursor CSP compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed Aug 10, 2023
1 parent a8158e0 commit 9f25ea9
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/Uno.UI/ts/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace Uno.UI {
private containerElement: HTMLDivElement;
private rootElement: HTMLElement;

private cursorStyleElement: HTMLElement;
private cursorStyleRule: CSSStyleRule;

private allActiveElementsById: { [id: string]: HTMLElement | SVGElement } = {};
private uiElementRegistrations: {
Expand Down Expand Up @@ -1731,22 +1731,16 @@ namespace Uno.UI {

if (unoBody) {

//always cleanup
if (this.cursorStyleElement != undefined) {
this.cursorStyleElement.remove();
this.cursorStyleElement = undefined
}

//only add custom overriding style if not auto
if (cssCursor != "auto") {
if (this.cursorStyleRule === undefined) {
const styleSheet = document.styleSheets[document.styleSheets.length - 1];

// this part is only to override default css: .uno-buttonbase {cursor: pointer;}
const ruleId = styleSheet.insertRule(".uno-buttonbase { }", styleSheet.cssRules.length);

this.cursorStyleElement = document.createElement("style");
this.cursorStyleElement.innerHTML = ".uno-buttonbase { cursor: " + cssCursor + "; }";
document.body.appendChild(this.cursorStyleElement);
this.cursorStyleRule = <CSSStyleRule>styleSheet.cssRules[ruleId];
}

this.cursorStyleRule.style.cursor = cssCursor !== "auto" ? cssCursor : null;

unoBody.style.cursor = cssCursor;
}
return "ok";
Expand Down

0 comments on commit 9f25ea9

Please sign in to comment.