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