Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit afbf78c

Browse files
authored
Merge pull request #1374 from ghiscoding/bugfix/dark-mode-grid-menu
fix: hide Toggle Dark Mode from Grid Menu by default
2 parents a20c213 + 5d529fd commit afbf78c

File tree

8 files changed

+67
-21
lines changed

8 files changed

+67
-21
lines changed

docs/styling/dark-mode.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,35 @@ this.compositeEditorInstance?.openDetails({
6464
});
6565
```
6666

67+
### Grid Menu
68+
By default there is no command for toggling the Dark Mode from the Grid Menu, however you can show the command at any time via the following settings:
69+
70+
```ts
71+
export class MyDemo {
72+
isDarkModeEnabled = false;
73+
74+
defineGrid() {
75+
this.gridOptions = {
76+
darkMode: this.isDarkModeEnabled,
77+
gridMenu: {
78+
hideToggleDarkModeCommand: false, // hidden by default
79+
80+
// you can optionally add extra command to toggle your own page styling as well
81+
onCommand: (_, args) => {
82+
// ...
83+
},
84+
85+
// you can also change the icon and/or command name
86+
iconToggleDarkModeCommand: 'fa fa-moon-o',
87+
commandLabels: {
88+
toggleDarkModeCommand: 'Toggle Dark Mode',
89+
},
90+
}
91+
};
92+
}
93+
}
94+
```
95+
6796
### Tweaking Some Colors
6897

6998
The Dark Mode Theme was created by setting a few CSS variables, in some cases you might need to tweak some of these variables. Take a look at the Slickgrid-Universal [CSS variables](https://github.com/ghiscoding/slickgrid-universal/blob/670946dcedd330a70d2e88127a0042474e7a5348/packages/common/src/styles/_variables.scss#L976-L985) to see which variables were reassigned. Also note that if you're using other Themes like Material or Salesforce, then there's also other variables that are set (see [Material variables](https://github.com/ghiscoding/slickgrid-universal/blob/670946dcedd330a70d2e88127a0042474e7a5348/packages/common/src/styles/_variables-theme-material.scss#L159-L189) or [Salesforce variables](https://github.com/ghiscoding/slickgrid-universal/blob/670946dcedd330a70d2e88127a0042474e7a5348/packages/common/src/styles/_variables-theme-salesforce.scss#L202-L219))

src/app/examples/grid-composite-editor.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div id="demo-container" class="container-fluid">
22
<h2>
33
{{title}}
4-
<button class="btn btn-outline-secondary btn-sm ms-3" (click)="toggleDarkModeGrid()"
4+
<button class="btn btn-outline-secondary btn-sm ms-3" (click)="toggleDarkMode()"
55
data-test="toggle-dark-mode">
66
<span>Toggle Dark Mode</span>
77
</button>

src/app/examples/grid-composite-editor.component.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const myCustomTitleValidator = (value: any, args: any) => {
8484
encapsulation: ViewEncapsulation.None,
8585
})
8686
export class GridCompositeEditorComponent implements OnDestroy, OnInit {
87-
private _darkModeGrid = false;
87+
private _darkMode = false;
8888
title = 'Example 30: Composite Editor Modal';
8989
subTitle = `Composite Editor allows you to Create, Clone, Edit, Mass Update & Mass Selection Changes inside a nice Modal Window.
9090
<br>The modal is simply populated by looping through your column definition list and also uses a lot of the same logic as inline editing (see <a href="https://ghiscoding.gitbook.io/angular-slickgrid/grid-functionalities/composite-editor-modal" target="_blank">Composite Editor - Wiki</a>.)`;
@@ -384,7 +384,7 @@ export class GridCompositeEditorComponent implements OnDestroy, OnInit {
384384
container: '#demo-container',
385385
rightPadding: 10
386386
},
387-
darkMode: this._darkModeGrid,
387+
darkMode: this._darkMode,
388388
enableAutoSizeColumns: true,
389389
enableAutoResize: true,
390390
showCustomFooter: true,
@@ -443,6 +443,15 @@ export class GridCompositeEditorComponent implements OnDestroy, OnInit {
443443
},
444444
// when using the cellMenu, you can change some of the default options and all use some of the callback methods
445445
enableCellMenu: true,
446+
gridMenu: {
447+
hideToggleDarkModeCommand: false, // hidden by default
448+
onCommand: (_, args) => {
449+
if (args.command === 'toggle-dark-mode') {
450+
this._darkMode = !this._darkMode; // keep local toggle var in sync
451+
this.toggleBodyBackground();
452+
}
453+
}
454+
}
446455
};
447456
}
448457

@@ -625,7 +634,7 @@ export class GridCompositeEditorComponent implements OnDestroy, OnInit {
625634
onRendered: (modalElm) => {
626635
// Bootstrap requires extra attribute when toggling Dark Mode (data-bs-theme="dark")
627636
// we need to manually add this attribute ourselve before opening the Composite Editor Modal
628-
modalElm.dataset.bsTheme = this._darkModeGrid ? 'dark' : 'light';
637+
modalElm.dataset.bsTheme = this._darkMode ? 'dark' : 'light';
629638
},
630639
onSave: (formValues, _selection, dataContext) => {
631640
const serverResponseDelay = 50;
@@ -762,16 +771,20 @@ export class GridCompositeEditorComponent implements OnDestroy, OnInit {
762771
this.editQueue = [];
763772
}
764773

765-
toggleDarkModeGrid() {
766-
this._darkModeGrid = !this._darkModeGrid;
767-
if (this._darkModeGrid) {
774+
toggleDarkMode() {
775+
this._darkMode = !this._darkMode;
776+
this.toggleBodyBackground();
777+
this.angularGrid.slickGrid?.setOptions({ darkMode: this._darkMode });
778+
}
779+
780+
toggleBodyBackground() {
781+
if (this._darkMode) {
768782
document.querySelector<HTMLDivElement>('.panel-wm-content')!.classList.add('dark-mode');
769783
document.querySelector<HTMLDivElement>('#demo-container')!.dataset.bsTheme = 'dark';
770784
} else {
771785
document.querySelector('.panel-wm-content')!.classList.remove('dark-mode');
772786
document.querySelector<HTMLDivElement>('#demo-container')!.dataset.bsTheme = 'light';
773787
}
774-
this.angularGrid.slickGrid?.setOptions({ darkMode: this._darkModeGrid });
775788
}
776789

777790
mockProducts() {

src/app/examples/grid-contextmenu.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="container-fluid">
22
<h2>
33
{{title}}
4-
<button class="btn btn-outline-secondary btn-sm ms-3" (click)="toggleDarkModeGrid()"
4+
<button class="btn btn-outline-secondary btn-sm ms-3" (click)="toggleDarkMode()"
55
data-test="toggle-dark-mode">
66
<span>Toggle Dark Mode</span>
77
</button>

src/app/examples/grid-contextmenu.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ export class GridContextMenuComponent implements OnInit, OnDestroy {
547547
);
548548
}
549549

550-
toggleDarkModeGrid() {
550+
toggleDarkMode() {
551551
this._darkModeGrid = !this._darkModeGrid;
552552
if (this._darkModeGrid) {
553553
document.querySelector<HTMLDivElement>('.panel-wm-content')!.classList.add('dark-mode');

src/app/modules/angular-slickgrid/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export class Constants {
6161
TEXT_SORT_ASCENDING: 'Sort Ascending',
6262
TEXT_SORT_DESCENDING: 'Sort Descending',
6363
TEXT_STARTS_WITH: 'Starts With',
64+
TEXT_TOGGLE_DARK_MODE: 'Toggle Dark Mode',
6465
TEXT_TOGGLE_FILTER_ROW: 'Toggle Filter Row',
6566
TEXT_TOGGLE_PRE_HEADER_ROW: 'Toggle Pre-Header Row',
6667
TEXT_X_OF_Y_SELECTED: '# of % selected',

src/app/modules/angular-slickgrid/global-grid-options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export const GlobalGridOptions: Partial<GridOption> = {
146146
exportExcelCommandKey: 'EXPORT_TO_EXCEL',
147147
exportTextDelimitedCommandKey: 'EXPORT_TO_TAB_DELIMITED',
148148
refreshDatasetCommandKey: 'REFRESH_DATASET',
149+
toggleDarkModeCommandKey: 'TOGGLE_DARK_MODE',
149150
toggleFilterCommandKey: 'TOGGLE_FILTER_ROW',
150151
togglePreHeaderCommandKey: 'TOGGLE_PRE_HEADER_ROW',
151152
},
@@ -158,6 +159,7 @@ export const GlobalGridOptions: Partial<GridOption> = {
158159
hideForceFitButton: false,
159160
hideRefreshDatasetCommand: false,
160161
hideSyncResizeButton: true,
162+
hideToggleDarkModeCommand: true,
161163
hideToggleFilterCommand: false,
162164
hideTogglePreHeaderCommand: false,
163165
iconCssClass: 'fa fa-bars',
@@ -168,6 +170,7 @@ export const GlobalGridOptions: Partial<GridOption> = {
168170
iconExportExcelCommand: 'fa fa-file-excel-o text-success',
169171
iconExportTextDelimitedCommand: 'fa fa-download',
170172
iconRefreshDatasetCommand: 'fa fa-refresh',
173+
iconToggleDarkModeCommand: 'fa fa-moon-o mdi mdi-brightness-4',
171174
iconToggleFilterCommand: 'fa fa-random',
172175
iconTogglePreHeaderCommand: 'fa fa-random',
173176
menuWidth: 16,

test/cypress/e2e/example17.cy.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe('Example 17 - Row Move & Checkbox Selector Selector Plugins', () => {
149149
cy.get('[data-test="toggle-filtering-btn"]').click(); // show it back
150150
});
151151

152-
it.skip('should expect "Clear all Filters" command to be hidden in the Grid Menu', () => {
152+
it('should expect "Clear all Filters" command to be hidden in the Grid Menu', () => {
153153
const expectedFullHeaderMenuCommands = ['Clear all Filters', 'Clear all Sorting', 'Toggle Filter Row', 'Export to Excel'];
154154

155155
cy.get('#grid17')
@@ -170,7 +170,7 @@ describe('Example 17 - Row Move & Checkbox Selector Selector Plugins', () => {
170170
});
171171
});
172172

173-
it.skip('should be able to toggle Filters functionality', () => {
173+
it('should be able to toggle Filters functionality', () => {
174174
const expectedTitles = ['', '', 'Title', '% Complete', 'Start', 'Finish', 'Completed', 'Title'];
175175

176176
cy.get('[data-test="toggle-filtering-btn"]').click(); // hide it
@@ -192,7 +192,7 @@ describe('Example 17 - Row Move & Checkbox Selector Selector Plugins', () => {
192192
.each(($child, index) => expect($child.text()).to.eq(expectedTitles[index]));
193193
});
194194

195-
it.skip('should be able to toggle Sorting functionality (disable) and expect all header menu Sorting commands to be hidden and also not show Sort hint while hovering a column', () => {
195+
it('should be able to toggle Sorting functionality (disable) and expect all header menu Sorting commands to be hidden and also not show Sort hint while hovering a column', () => {
196196
const expectedFullHeaderMenuCommands = ['Resize by Content', '', 'Sort Ascending', 'Sort Descending', '', 'Remove Filter', 'Remove Sort', 'Hide Column'];
197197

198198
cy.get('.slick-sort-indicator').should('have.length.greaterThan', 0); // sort icon hints
@@ -220,7 +220,7 @@ describe('Example 17 - Row Move & Checkbox Selector Selector Plugins', () => {
220220
});
221221
});
222222

223-
it.skip('should expect "Clear Sorting" command to be hidden in the Grid Menu', () => {
223+
it('should expect "Clear Sorting" command to be hidden in the Grid Menu', () => {
224224
const expectedFullHeaderMenuCommands = ['Clear all Filters', 'Clear all Sorting', 'Toggle Filter Row', 'Export to Excel'];
225225

226226
cy.get('#grid17')
@@ -241,7 +241,7 @@ describe('Example 17 - Row Move & Checkbox Selector Selector Plugins', () => {
241241
});
242242
});
243243

244-
it.skip('should be able to toggle Sorting functionality (re-enable) and expect all Sorting header menu commands to be hidden and also not show Sort hint while hovering a column', () => {
244+
it('should be able to toggle Sorting functionality (re-enable) and expect all Sorting header menu commands to be hidden and also not show Sort hint while hovering a column', () => {
245245
const expectedFullHeaderMenuCommands = ['Resize by Content', '', 'Sort Ascending', 'Sort Descending', '', 'Remove Filter', 'Remove Sort', 'Hide Column'];
246246

247247
cy.get('.slick-sort-indicator').should('have.length', 0); // sort icon hints
@@ -265,7 +265,7 @@ describe('Example 17 - Row Move & Checkbox Selector Selector Plugins', () => {
265265
});
266266
});
267267

268-
it.skip('should expect "Clear Sorting" command to be hidden in the Grid Menu', () => {
268+
it('should expect "Clear Sorting" command to be hidden in the Grid Menu', () => {
269269
const expectedFullHeaderMenuCommands = ['Clear all Filters', 'Clear all Sorting', 'Toggle Filter Row', 'Export to Excel'];
270270

271271
cy.get('#grid17')
@@ -286,7 +286,7 @@ describe('Example 17 - Row Move & Checkbox Selector Selector Plugins', () => {
286286
});
287287
});
288288

289-
it.skip('should be able to click disable Sorting functionality button and expect all Sorting commands to be hidden and also not show Sort hint while hovering a column', () => {
289+
it('should be able to click disable Sorting functionality button and expect all Sorting commands to be hidden and also not show Sort hint while hovering a column', () => {
290290
const expectedFullHeaderMenuCommands = ['Resize by Content', '', 'Sort Ascending', 'Sort Descending', '', 'Remove Filter', 'Remove Sort', 'Hide Column'];
291291

292292
cy.get('.slick-sort-indicator').should('have.length.greaterThan', 0); // sort icon hints
@@ -314,7 +314,7 @@ describe('Example 17 - Row Move & Checkbox Selector Selector Plugins', () => {
314314
});
315315
});
316316

317-
it.skip('should be able to click disable Filter functionality button and expect all Filter commands to be hidden and also not show Sort hint while hovering a column', () => {
317+
it('should be able to click disable Filter functionality button and expect all Filter commands to be hidden and also not show Sort hint while hovering a column', () => {
318318
const expectedFullHeaderMenuCommands = ['Resize by Content', '', 'Sort Ascending', 'Sort Descending', '', 'Remove Filter', 'Remove Sort', 'Hide Column'];
319319

320320
cy.get('[data-test="disable-filters-btn"]').click().click(); // even clicking twice should have same result
@@ -340,7 +340,7 @@ describe('Example 17 - Row Move & Checkbox Selector Selector Plugins', () => {
340340
});
341341
});
342342

343-
it.skip('should expect "Clear all Filters" command to be hidden in the Grid Menu', () => {
343+
it('should expect "Clear all Filters" command to be hidden in the Grid Menu', () => {
344344
const expectedFullHeaderMenuCommands = ['Clear all Filters', 'Clear all Sorting', 'Toggle Filter Row', 'Export to Excel'];
345345

346346
cy.get('#grid17')
@@ -361,7 +361,7 @@ describe('Example 17 - Row Move & Checkbox Selector Selector Plugins', () => {
361361
});
362362
});
363363

364-
it.skip('should open Column Picker and show the "Duration" column back to visible and expect it to have kept its position after toggling filter/sorting', () => {
364+
it('should open Column Picker and show the "Duration" column back to visible and expect it to have kept its position after toggling filter/sorting', () => {
365365
// first 2 cols are hidden but they do count as li item
366366
const expectedFullPickerTitles = ['', '', 'Title', '% Complete', 'Start', 'Finish', 'Duration', 'Completed'];
367367

@@ -404,7 +404,7 @@ describe('Example 17 - Row Move & Checkbox Selector Selector Plugins', () => {
404404
});
405405
});
406406

407-
it.skip('should add Edit/Delete columns and expect 2 new columns added at the beginning of the grid', () => {
407+
it('should add Edit/Delete columns and expect 2 new columns added at the beginning of the grid', () => {
408408
const newExpectedColumns = ['', '', ...fullTitles];
409409
cy.get('[data-test="add-crud-columns-btn"]').click();
410410

0 commit comments

Comments
 (0)