Merge "Add keyboard shortcuts to account dropdown"
This commit is contained in:
@@ -90,7 +90,9 @@ class GrAccountDropdown extends mixinBehaviors( [
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const links = [{name: 'Settings', url: '/settings/'}];
|
||||
const links = [];
|
||||
links.push({name: 'Settings', url: '/settings/'});
|
||||
links.push({name: 'Keyboard Shortcuts', id: 'shortcuts'});
|
||||
if (switchAccountUrl) {
|
||||
const replacements = {path};
|
||||
const url = this._interpolateUrl(switchAccountUrl, replacements);
|
||||
@@ -107,6 +109,11 @@ class GrAccountDropdown extends mixinBehaviors( [
|
||||
];
|
||||
}
|
||||
|
||||
_handleShortcutsTap(e) {
|
||||
this.dispatchEvent(new CustomEvent('show-keyboard-shortcuts',
|
||||
{bubbles: true, composed: true}));
|
||||
}
|
||||
|
||||
_handleLocationChange() {
|
||||
this._path =
|
||||
window.location.pathname +
|
||||
|
||||
@@ -37,6 +37,7 @@ export const htmlTemplate = html`
|
||||
link=""
|
||||
items="[[links]]"
|
||||
top-content="[[topContent]]"
|
||||
on-tap-item-shortcuts="_handleShortcutsTap"
|
||||
horizontal-align="right"
|
||||
>
|
||||
<span hidden$="[[_hasAvatars]]" hidden="">[[_accountName(account)]]</span>
|
||||
|
||||
@@ -84,12 +84,12 @@ suite('gr-account-dropdown tests', () => {
|
||||
assert.isUndefined(element._getLinks(null));
|
||||
|
||||
// No switch account link.
|
||||
assert.equal(element._getLinks(null, '').length, 2);
|
||||
assert.equal(element._getLinks(null, '').length, 3);
|
||||
|
||||
// Unparameterized switch account link.
|
||||
let links = element._getLinks('/switch-account', '');
|
||||
assert.equal(links.length, 3);
|
||||
assert.deepEqual(links[1], {
|
||||
assert.equal(links.length, 4);
|
||||
assert.deepEqual(links[2], {
|
||||
name: 'Switch account',
|
||||
url: '/switch-account',
|
||||
external: true,
|
||||
@@ -97,8 +97,8 @@ suite('gr-account-dropdown tests', () => {
|
||||
|
||||
// Parameterized switch account link.
|
||||
links = element._getLinks('/switch-account${path}', '/c/123');
|
||||
assert.equal(links.length, 3);
|
||||
assert.deepEqual(links[1], {
|
||||
assert.equal(links.length, 4);
|
||||
assert.deepEqual(links[2], {
|
||||
name: 'Switch account',
|
||||
url: '/switch-account/c/123',
|
||||
external: true,
|
||||
|
||||
@@ -499,6 +499,10 @@ class GrAppElement extends mixinBehaviors( [
|
||||
}
|
||||
}
|
||||
|
||||
handleShowKeyboardShortcuts() {
|
||||
this.$.keyboardShortcuts.open();
|
||||
}
|
||||
|
||||
_showKeyboardShortcuts(e) {
|
||||
// same shortcut should close the dialog if pressed again
|
||||
// when dialog is open
|
||||
|
||||
@@ -104,6 +104,7 @@ export const htmlTemplate = html`
|
||||
id="mainHeader"
|
||||
search-query="{{params.query}}"
|
||||
on-mobile-search="_mobileSearchToggle"
|
||||
on-show-keyboard-shortcuts="handleShowKeyboardShortcuts"
|
||||
login-url="[[_loginUrl]]"
|
||||
>
|
||||
</gr-main-header>
|
||||
|
||||
@@ -292,7 +292,8 @@ class GrDropdown extends mixinBehaviors( [
|
||||
const item = this.items.find(item => item.id === id);
|
||||
if (id && !this.disabledIds.includes(id)) {
|
||||
if (item) {
|
||||
this.dispatchEvent(new CustomEvent('tap-item', {detail: item}));
|
||||
this.dispatchEvent(new CustomEvent('tap-item',
|
||||
{detail: item, bubbles: true, composed: true}));
|
||||
}
|
||||
this.dispatchEvent(new CustomEvent('tap-item-' + id));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user