Merge pull request #16570 from resilient-tech/fix-theme-switcher

fix: theme switcher shortcut issue
This commit is contained in:
mergify[bot] 2022-04-11 11:26:56 +00:00 committed by GitHub
commit 31d87176c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 2 deletions

View file

@ -0,0 +1,30 @@
context('Theme Switcher Shortcut', () => {
before(() => {
cy.login();
cy.visit('/app');
});
beforeEach(() => {
cy.reload();
});
it('Check Toggle', () => {
cy.open_theme_dialog('{ctrl+shift+g}');
cy.get('.modal-backdrop').should('exist');
cy.get('.theme-grid > div').first().click();
cy.close_theme('{ctrl+shift+g}');
cy.get('.modal-backdrop').should('not.exist');
});
it('Check Enter', () => {
cy.open_theme_dialog('{ctrl+shift+g}');
cy.get('.theme-grid > div').first().click();
cy.close_theme('{enter}');
cy.get('.modal-backdrop').should('not.exist');
});
});
Cypress.Commands.add('open_theme_dialog', (shortcut_keys) => {
cy.get('body').type(shortcut_keys);
});
Cypress.Commands.add('close_theme', (shortcut_keys) => {
cy.get('.modal-header').type(shortcut_keys);
});

View file

@ -59,8 +59,12 @@ frappe.Application = class Application {
shortcut: 'shift+ctrl+g',
description: __('Switch Theme'),
action: () => {
frappe.theme_switcher = new frappe.ui.ThemeSwitcher();
frappe.theme_switcher.show();
if (frappe.theme_switcher && frappe.theme_switcher.dialog.is_visible) {
frappe.theme_switcher.hide();
} else {
frappe.theme_switcher = new frappe.ui.ThemeSwitcher();
frappe.theme_switcher.show();
}
}
});

View file

@ -25,6 +25,8 @@ frappe.ui.ThemeSwitcher = class ThemeSwitcher {
increment_by = 1;
} else if (key === "left") {
increment_by = -1;
} else if (e.keyCode === 13) { // keycode 13 is for 'enter'
this.hide();
} else {
return;
}