Skip to content

Commit c76b790

Browse files
authoredOct 25, 2024
docs: turn off forced colors mode in website (SAP#10085)
Windows Contrast themes adjust colors of UI5 Web Components which leads to poor visual. The PR fixes the issue for the playground samples setting `forced-color-adjust` to `none`. The property allows authors to opt certain elements out of forced colors mode as explained in [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/forced-color-adjust). And adds suggestion for fixing it in apps the same way. We don't own the page and we believe this is in the apps domain to set it. Fixes: SAP#9436 SAP#9917
1 parent b5e596e commit c76b790

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed
 

‎docs/09-FAQ.md

+22
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,25 @@ ui5-button:not(:defined), ui5-label:not(:defined) {
8585
```
8686

8787
Please note that the `:defined` CSS pseudo-selector is not supported by the Edge and Internet Explorer 11 browsers.
88+
89+
**Q: How can opt out of forced colors mode. How to avoid Web Components from being adjusted by the user agent forced colors mode?**
90+
91+
**A:** You can use the following CSS rule, based on the `forced-color-adjust` CSS prop:
92+
93+
```CSS
94+
html {
95+
forced-color-adjust: none;
96+
}
97+
```
98+
99+
or to be more precise, you can apply the CSS rule when `forced-colors` mode is `active`:
100+
101+
```CSS
102+
@media (forced-colors: active) {
103+
.html {
104+
forced-color-adjust: none;
105+
}
106+
}
107+
```
108+
109+
By setting `forced-color-adjust` to `none`, the element's colors will not be automatically adjusted by the user agent in forced colors mode.

‎packages/website/src/components/Editor/index.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export default function Editor({html, js, css, mainFile = "main.js", canShare =
9393
}
9494
}
9595

96-
function addImportMap(html) {
96+
function addHeadContent(html) {
9797
return html.replace("<head>", `
9898
<head>
9999
<script type="importmap">
@@ -105,6 +105,10 @@ export default function Editor({html, js, css, mainFile = "main.js", canShare =
105105
*:not(:defined) {
106106
display: none;
107107
}
108+
109+
html {
110+
forced-color-adjust: none;
111+
}
108112
</style>
109113
`)
110114
}
@@ -231,7 +235,7 @@ export default function Editor({html, js, css, mainFile = "main.js", canShare =
231235
let newConfig = {
232236
files: {
233237
"index.html": {
234-
content: addImportMap(fixAssetPaths(_html)),
238+
content: addHeadContent(fixAssetPaths(_html)),
235239
},
236240
"playground-support.js": {
237241
content: playgroundSupport({theme, textDirection, contentDensity, iframeId}),
@@ -263,7 +267,7 @@ ${fixAssetPaths(_js)}`,
263267
if (savedProject) {
264268
try {
265269
const savedConfig = JSON.parse(savedProject);
266-
savedConfig["index.html"].content = addImportMap(fixAssetPaths(savedConfig["index.html"].content));
270+
savedConfig["index.html"].content = addHeadContent(fixAssetPaths(savedConfig["index.html"].content));
267271
if (savedConfig["main.js"] && newConfig.files["main.ts"]) {
268272
delete newConfig.files["main.ts"];
269273
}
@@ -278,7 +282,7 @@ ${fixAssetPaths(_js)}`,
278282
if (location.pathname.includes("/play") && location.hash) {
279283
try {
280284
const sharedConfig = JSON.parse(decodeFromBase64(location.hash.replace("#", "")));
281-
sharedConfig["index.html"].content = addImportMap(fixAssetPaths(sharedConfig["index.html"].content));
285+
sharedConfig["index.html"].content = addHeadContent(fixAssetPaths(sharedConfig["index.html"].content));
282286
if (sharedConfig["main.js"] && newConfig.files["main.ts"]) {
283287
delete newConfig.files["main.ts"];
284288
}

0 commit comments

Comments
 (0)
Please sign in to comment.