Commit 18f718a1 authored by Gavin Williams's avatar Gavin Williams Committed by Commit Bot

Remove cr-input from CrOS destination dropdown

cr-input is mainly used for receiving user keyboard input and comes
with a lot of built-in features to support that. Since the print
preview dropdown does not directly receive keyboard input it makes
sense to replace cr-input with a standard div. This makes customization
of the dropdown cleaner as well.

"input" was removed from all of the element id's to reflect the removal
of cr-input.

Bug: 1059607
Change-Id: Icdbde1ac3e089fc76b35eef2ba67f76a4f649fe3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2284866Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786604}
parent eb197564
<style include="cr-shared-style cr-hidden-style md-select"> <style include="cr-shared-style cr-hidden-style">
:host([opened_]) cr-input {
--cr-input-border-radius: 4px 4px 0 0;
}
iron-dropdown,
cr-input {
width: var(--md-select-width);
}
cr-input::part(input) {
cursor: pointer;
opacity: 1;
padding-inline-end: 32px;
padding-inline-start: 8px;
text-overflow: clip;
}
iron-dropdown { iron-dropdown {
border: 0.5px solid rgba(0, 0, 0, 0.5); border: 0.5px solid rgba(0, 0, 0, 0.5);
max-height: 270px; max-height: 270px;
...@@ -24,27 +7,14 @@ ...@@ -24,27 +7,14 @@
iron-dropdown [slot='dropdown-content'] { iron-dropdown [slot='dropdown-content'] {
background-color: white; background-color: white;
box-shadow: 0 2px 6px var(--google-grey-600); box-shadow: 0 2px 6px var(--google-grey-600);
min-width: var(--md-select-width);
padding: 8px 0; padding: 8px 0;
} }
#input-overlay {
border-radius: 4px;
height: 100%;
left: 0;
overflow: hidden;
pointer-events: none;
position: absolute;
top: 0;
width: 100%;
}
#dropdown-icon { #dropdown-icon {
--iron-icon-height: 20px; --iron-icon-height: 24px;
--iron-icon-width: 20px; --iron-icon-width: 44px;
margin-top: -10px; align-items: center;
padding-inline-end: 6px; margin-inline-start: -4px;
position: absolute;
right: 0; right: 0;
top: 50%; top: 50%;
} }
...@@ -54,20 +24,15 @@ ...@@ -54,20 +24,15 @@
right: unset; right: unset;
} }
cr-input:focus-within #dropdown-icon { #dropdown-box {
--iron-icon-fill-color: var(--google-blue-600); border-radius: 4px;
}
#input-box {
height: 100%; height: 100%;
left: 0; left: 0;
pointer-events: none; margin-top: 24px;
top: 0; overflow: hidden;
width: 100%;
}
#dropdown-box {
pointer-events: initial; pointer-events: initial;
position: absolute;
top: 0;
width: 100%; width: 100%;
} }
...@@ -91,27 +56,37 @@ ...@@ -91,27 +56,37 @@
background-color: var(--google-blue-refresh-100); background-color: var(--google-blue-refresh-100);
} }
.dot { #destination-icon-box,
background-color: #bbb;
border-radius: 50%;
display: inline-block;
height: 10px;
width: 10px;
}
#pre-input-box,
.printer-display-name { .printer-display-name {
padding-inline-start: 8px; padding-inline-start: 8px;
} }
#pre-input-box { #destination-dropdown {
position: relative;
}
#destination-display-container {
align-items: center;
background-color: var(--google-grey-refresh-100);
border-radius: 4px;
cursor: pointer; cursor: pointer;
display: flex;
width: 100%;
}
#destination-display {
box-sizing: border-box;
overflow: hidden;
padding-inline-end: 32px;
padding-inline-start: 8px;
text-overflow: clip;
white-space: nowrap;
width: 100%;
} }
</style> </style>
<cr-input id="dropdownInput" on-keydown="onKeyDown_" <div id="destination-dropdown" on-keydown="onKeyDown_" tabindex="0">
value="[[value.displayName]]" disabled="[[disabled]]" readonly> <div id="destination-display-container">
<div id="pre-input-overlay" slot="inline-prefix"> <div id="destination-icon-box">
<div id="pre-input-box">
<iron-icon icon="[[destinationIcon]]" <iron-icon icon="[[destinationIcon]]"
hidden="[[isCurrentDestinationCrosLocal]]"> hidden="[[isCurrentDestinationCrosLocal]]">
</iron-icon> </iron-icon>
...@@ -121,43 +96,40 @@ ...@@ -121,43 +96,40 @@
value.printerStatusReason)]]"> value.printerStatusReason)]]">
</printer-status-icon-cros> </printer-status-icon-cros>
</div> </div>
<div id="destination-display">[[value.displayName]]</div>
<iron-icon id="dropdown-icon" icon="cr:arrow-drop-down"></iron-icon>
</div> </div>
<div id="input-overlay" slot="suffix"> <div id="dropdown-box">
<div id="input-box"> <iron-dropdown horizontal-align="left" vertical-align="top"
<iron-icon id="dropdown-icon" icon="cr:arrow-drop-down"></iron-icon> vertical-offset="0" no-cancel-on-outside-click
</div> no-cancel-on-esc-key>
<div id="dropdown-box"> <div slot="dropdown-content">
<iron-dropdown horizontal-align="left" vertical-align="top" <template is="dom-repeat" items="[[itemList]]">
vertical-offset="0" no-cancel-on-outside-click <button id="[[item.key]]" class="list-item" on-click="onSelect_"
no-cancel-on-esc-key> tabindex="-1" value="[[item.key]]">
<div slot="dropdown-content"> <printer-status-icon-cros background="white"
<template is="dom-repeat" items="[[itemList]]"> state$="[[computePrinterState_(item.printerStatusReason)]]">
<button id="[[item.key]]" class="list-item" on-click="onSelect_" </printer-status-icon-cros>
tabindex="-1" value="[[item.key]]"> <span class="printer-display-name">[[item.displayName]]</span>
<printer-status-icon-cros background="white"
state$="[[computePrinterState_(item.printerStatusReason)]]">
</printer-status-icon-cros>
<span class="printer-display-name">[[item.displayName]]</span>
</button>
</template>
<button class="list-item" on-click="onSelect_" tabindex="-1"
value="[[pdfDestinationKey]]" hidden$="[[pdfPrinterDisabled]]">
$i18n{printToPDF}
</button>
<button class="list-item" on-click="onSelect_" tabindex="-1"
value="[[driveDestinationKey]]" hidden$="[[!driveDestinationKey]]">
$i18n{printToGoogleDrive}
</button> </button>
<button class="list-item" on-click="onSelect_" tabindex="-1" </template>
value="noDestinations" hidden$="[[!noDestinations]]"> <button class="list-item" on-click="onSelect_" tabindex="-1"
$i18n{noDestinationsMessage} value="[[pdfDestinationKey]]" hidden$="[[pdfPrinterDisabled]]">
</button> $i18n{printToPDF}
<button class="list-item" on-click="onSelect_" tabindex="-1" </button>
value="seeMore" aria-label$="[[i18n(seeMoreDestinationsLabel)]]"> <button class="list-item" on-click="onSelect_" tabindex="-1"
$i18n{seeMore} value="[[driveDestinationKey]]" hidden$="[[!driveDestinationKey]]">
</button> $i18n{printToGoogleDrive}
</div> </button>
</iron-dropdown> <button class="list-item" on-click="onSelect_" tabindex="-1"
</div> value="noDestinations" hidden$="[[!noDestinations]]">
$i18n{noDestinationsMessage}
</button>
<button class="list-item" on-click="onSelect_" tabindex="-1"
value="seeMore" aria-label$="[[i18n(seeMoreDestinationsLabel)]]">
$i18n{seeMore}
</button>
</div>
</iron-dropdown>
</div> </div>
</cr-input> </div>
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'chrome://resources/cr_elements/cr_input/cr_input.m.js';
import 'chrome://resources/cr_elements/hidden_style_css.m.js'; import 'chrome://resources/cr_elements/hidden_style_css.m.js';
import 'chrome://resources/cr_elements/md_select_css.m.js';
import 'chrome://resources/cr_elements/shared_vars_css.m.js'; import 'chrome://resources/cr_elements/shared_vars_css.m.js';
// TODO(gavinwill): Remove iron-dropdown dependency https://crbug.com/1082587. // TODO(gavinwill): Remove iron-dropdown dependency https://crbug.com/1082587.
import 'chrome://resources/polymer/v3_0/iron-dropdown/iron-dropdown.js'; import 'chrome://resources/polymer/v3_0/iron-dropdown/iron-dropdown.js';
...@@ -142,8 +140,8 @@ Polymer({ ...@@ -142,8 +140,8 @@ Polymer({
const paths = event.composedPath(); const paths = event.composedPath();
const dropdown = const dropdown =
/** @type {!IronDropdownElement} */ (this.$$('iron-dropdown')); /** @type {!IronDropdownElement} */ (this.$$('iron-dropdown'));
const dropdownInput = const destinationDropdown =
/** @type {!CrInputElement} */ (this.$$('#dropdownInput')); /** @type {!Element} */ (this.$$('#destination-dropdown'));
// Exit if path includes |dropdown| because event will be handled by // Exit if path includes |dropdown| because event will be handled by
// onSelect_. // onSelect_.
...@@ -151,7 +149,7 @@ Polymer({ ...@@ -151,7 +149,7 @@ Polymer({
return; return;
} }
if (!paths.includes(dropdownInput) || dropdown.opened) { if (!paths.includes(destinationDropdown) || dropdown.opened) {
this.closeDropdown_(); this.closeDropdown_();
return; return;
} }
......
...@@ -48,9 +48,18 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -48,9 +48,18 @@ suite(destination_dropdown_cros_test.suiteName, function() {
return dropdown.shadowRoot.querySelectorAll('.list-item'); return dropdown.shadowRoot.querySelectorAll('.list-item');
} }
/** @param {?Element} element */ function clickDropdown() {
function pointerDown(element) { dropdown.$$('#destination-dropdown')
element.dispatchEvent(new PointerEvent('pointerdown', { .dispatchEvent(new PointerEvent('pointerdown', {
bubbles: true,
cancelable: true,
composed: true,
buttons: 1,
}));
}
function clickOutsideDropdown() {
document.body.dispatchEvent(new PointerEvent('pointerdown', {
bubbles: true, bubbles: true,
cancelable: true, cancelable: true,
composed: true, composed: true,
...@@ -59,19 +68,20 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -59,19 +68,20 @@ suite(destination_dropdown_cros_test.suiteName, function() {
} }
function down() { function down() {
keyDownOn(dropdown.$$('#dropdownInput'), 'ArrowDown', [], 'ArrowDown'); keyDownOn(
dropdown.$$('#destination-dropdown'), 'ArrowDown', [], 'ArrowDown');
} }
function up() { function up() {
keyDownOn(dropdown.$$('#dropdownInput'), 'ArrowUp', [], 'ArrowUp'); keyDownOn(dropdown.$$('#destination-dropdown'), 'ArrowUp', [], 'ArrowUp');
} }
function enter() { function enter() {
keyDownOn(dropdown.$$('#dropdownInput'), 'Enter', [], 'Enter'); keyDownOn(dropdown.$$('#destination-dropdown'), 'Enter', [], 'Enter');
} }
function tab() { function tab() {
keyDownOn(dropdown.$$('#dropdownInput'), 'Tab', [], 'Tab'); keyDownOn(dropdown.$$('#destination-dropdown'), 'Tab', [], 'Tab');
} }
/** @return {?Element} */ /** @return {?Element} */
...@@ -145,17 +155,17 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -145,17 +155,17 @@ suite(destination_dropdown_cros_test.suiteName, function() {
dropdown.value = destinationOne; dropdown.value = destinationOne;
const ironDropdown = dropdown.$$('iron-dropdown'); const ironDropdown = dropdown.$$('iron-dropdown');
pointerDown(dropdown.$$('#dropdownInput')); clickDropdown();
assertTrue(ironDropdown.opened); assertTrue(ironDropdown.opened);
getList()[0].click(); getList()[0].click();
assertFalse(ironDropdown.opened); assertFalse(ironDropdown.opened);
pointerDown(dropdown.$$('#dropdownInput')); clickDropdown();
assertTrue(ironDropdown.opened); assertTrue(ironDropdown.opened);
// Click outside dropdown to close the dropdown. // Click outside dropdown to close the dropdown.
pointerDown(document.body); clickOutsideDropdown();
assertFalse(ironDropdown.opened); assertFalse(ironDropdown.opened);
}); });
...@@ -165,7 +175,7 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -165,7 +175,7 @@ suite(destination_dropdown_cros_test.suiteName, function() {
dropdown.value = destinationOne; dropdown.value = destinationOne;
const ironDropdown = dropdown.$$('iron-dropdown'); const ironDropdown = dropdown.$$('iron-dropdown');
pointerDown(dropdown.$$('#dropdownInput')); clickDropdown();
assertTrue(ironDropdown.opened); assertTrue(ironDropdown.opened);
tab(); tab();
...@@ -178,7 +188,7 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -178,7 +188,7 @@ suite(destination_dropdown_cros_test.suiteName, function() {
const destinationOne = createDestination('One', DestinationOrigin.CROS); const destinationOne = createDestination('One', DestinationOrigin.CROS);
setItemList([destinationOne]); setItemList([destinationOne]);
dropdown.value = destinationOne; dropdown.value = destinationOne;
pointerDown(dropdown.$$('#dropdownInput')); clickDropdown();
assertEquals('One', getHighlightedElementText()); assertEquals('One', getHighlightedElementText());
down(); down();
...@@ -255,7 +265,7 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -255,7 +265,7 @@ suite(destination_dropdown_cros_test.suiteName, function() {
createDestination('Three', DestinationOrigin.CROS) createDestination('Three', DestinationOrigin.CROS)
]); ]);
dropdown.value = destinationOne; dropdown.value = destinationOne;
pointerDown(dropdown.$$('#dropdownInput')); clickDropdown();
move(getList()[1], {x: 0, y: 0}, {x: 0, y: 0}, 1); move(getList()[1], {x: 0, y: 0}, {x: 0, y: 0}, 1);
assertEquals('Two', getHighlightedElementText()); assertEquals('Two', getHighlightedElementText());
...@@ -278,11 +288,11 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -278,11 +288,11 @@ suite(destination_dropdown_cros_test.suiteName, function() {
dropdown.value = destinationOne; dropdown.value = destinationOne;
dropdown.disabled = true; dropdown.disabled = true;
pointerDown(dropdown.$$('#dropdownInput')); clickDropdown();
assertFalse(dropdown.$$('iron-dropdown').opened); assertFalse(dropdown.$$('iron-dropdown').opened);
dropdown.disabled = false; dropdown.disabled = false;
pointerDown(dropdown.$$('#dropdownInput')); clickDropdown();
assertTrue(dropdown.$$('iron-dropdown').opened); assertTrue(dropdown.$$('iron-dropdown').opened);
}); });
...@@ -345,12 +355,12 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -345,12 +355,12 @@ suite(destination_dropdown_cros_test.suiteName, function() {
]); ]);
dropdown.value = destinationTwo; dropdown.value = destinationTwo;
pointerDown(dropdown.$$('#dropdownInput')); clickDropdown();
assertEquals('Two', getHighlightedElementText()); assertEquals('Two', getHighlightedElementText());
pointerDown(dropdown.$$('#dropdownInput')); clickDropdown();
dropdown.value = destinationThree; dropdown.value = destinationThree;
pointerDown(dropdown.$$('#dropdownInput')); clickDropdown();
assertEquals('Three', getHighlightedElementText()); assertEquals('Three', getHighlightedElementText());
}); });
}); });
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