Commit f7a9975a authored by dpapad's avatar dpapad Committed by Commit Bot

PDF Viewer update: Close overflow menu when an action is triggered.

Bug: 1121475
Change-Id: I46fe72ffe1ecedbc6dd939d314fe2befb83e8df3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2374605
Commit-Queue: John Lee <johntlee@chromium.org>
Auto-Submit: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarJohn Lee <johntlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801524}
parent f985905e
......@@ -112,6 +112,15 @@ export class ViewerPdfToolbarNewElement extends PolymerElement {
this.zoomTimeout_ = null;
}
/**
* @return {!CrActionMenuElement}
* @private
*/
getMenu_() {
return /** @type {!CrActionMenuElement} */ (
this.shadowRoot.querySelector('cr-action-menu'));
}
/** @private */
onSidenavToggleClick_() {
this.dispatchEvent(new CustomEvent('sidenav-toggle-click'));
......@@ -173,6 +182,7 @@ export class ViewerPdfToolbarNewElement extends PolymerElement {
this.displayAnnotations_ = !this.displayAnnotations_;
this.dispatchEvent(new CustomEvent(
'display-annotations-changed', {detail: this.displayAnnotations_}));
this.getMenu_().close();
// <if expr="chromeos">
if (!this.displayAnnotations_ && this.annotationMode) {
......@@ -209,12 +219,14 @@ export class ViewerPdfToolbarNewElement extends PolymerElement {
onSinglePageViewClick_() {
this.twoUpViewEnabled_ = false;
this.dispatchEvent(new CustomEvent('two-up-view-changed', {detail: false}));
this.getMenu_().close();
}
/** @private */
onTwoPageViewClick_() {
this.twoUpViewEnabled_ = true;
this.dispatchEvent(new CustomEvent('two-up-view-changed', {detail: true}));
this.getMenu_().close();
}
/** @private */
......@@ -298,8 +310,9 @@ export class ViewerPdfToolbarNewElement extends PolymerElement {
/** @private */
onMoreClick_() {
const menu = this.shadowRoot.querySelector('cr-action-menu');
menu.showAt(this.shadowRoot.querySelector('#more'), {
const anchor =
/** @type {!HTMLElement} */ (this.shadowRoot.querySelector('#more'));
this.getMenu_().showAt(anchor, {
anchorAlignmentX: AnchorAlignment.CENTER,
anchorAlignmentY: AnchorAlignment.AFTER_END,
noOffset: true,
......
......@@ -149,6 +149,26 @@ const tests = [
zoomField.dispatchEvent(new CustomEvent('input'));
},
// Test that the overflow menu closes when an action is triggered.
function testOverflowMenuCloses() {
const toolbar = createToolbar();
const menu = toolbar.shadowRoot.querySelector('cr-action-menu');
chrome.test.assertFalse(menu.open);
const more = toolbar.shadowRoot.querySelector('#more');
const buttons = menu.querySelectorAll('.dropdown-item');
chrome.test.assertTrue(buttons.length > 0);
for (const button of buttons) {
// Open overflow menu.
more.click();
chrome.test.assertTrue(menu.open);
button.click();
chrome.test.assertFalse(menu.open);
}
chrome.test.succeed();
},
function testSinglePageView() {
const toolbar = createToolbar();
const singlePageViewButton =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment