Skip to content

Commit c2da72b

Browse files
Init the attribute data-ag-theme-mode of ui.aggrid before themeObserver created (zauberzeug#5306)
### Motivation If `ui.aggrid` was created in a page with dark mode, `ui.aggrid`'s theme won't be dark mode unless resizing page. <!-- What problem does this PR solve? Which new feature or improvement does it implement? --> <!-- Please provide relevant links to corresponding issues and feature requests. --> ### Implementation Add `this.$el.setAttribute("data-ag-theme-mode", document.body.classList.contains("body--dark") ? "dark" : "light")` to aggrid.js line 8. Before themeObserver created, init the attribute `data-ag-theme-mode` of `ui.aggrid`. <!-- What is the concept behind the implementation? How does it work? --> <!-- Include any important technical decisions or trade-offs made --> ### Progress - [x] I chose a meaningful title that completes the sentence: "If applied, this PR will..." - [x] The implementation is complete. - [x] Pytests have been added (or are not necessary). - [x] Documentation has been added (or is not necessary). --------- Co-authored-by: Falko Schindler <[email protected]>
1 parent 3a94186 commit c2da72b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

nicegui/elements/aggrid/aggrid.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ export default {
66
mounted() {
77
this.update_grid();
88

9-
this.themeObserver = new MutationObserver(() =>
10-
this.$el.setAttribute("data-ag-theme-mode", document.body.classList.contains("body--dark") ? "dark" : "light")
11-
);
9+
const updateTheme = () =>
10+
this.$el.setAttribute("data-ag-theme-mode", document.body.classList.contains("body--dark") ? "dark" : "light");
11+
this.themeObserver = new MutationObserver(updateTheme);
1212
this.themeObserver.observe(document.body, { attributes: true, attributeFilter: ["class"] });
13+
updateTheme();
1314
},
1415
unmounted() {
1516
this.themeObserver.disconnect();

0 commit comments

Comments
 (0)