Commit e672f8c2 authored by Roman Arora's avatar Roman Arora Committed by Josip Sokcevic

Tab Search: Enable Close Tab button & click behavior.

Close button focus and navigation aspects to be addressed in crbug
1113470.

Bug: 1099917
Change-Id: I7f42dd62381a345eb0cf807c48d5f8eb3b79b70e
Reviewed-on: https://chrome-internal-review.googlesource.com/c/chrome/browser/resources/tab_search/+/3203733Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarTom Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819581}
parent 8658da38
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<iron-selector id="selector" selected="{{selectedIndex_}}" selected-class="selected"> <iron-selector id="selector" selected="{{selectedIndex_}}" selected-class="selected">
<template id="tabs-list" is="dom-repeat" items="[[filteredOpenTabs_]]"> <template id="tabs-list" is="dom-repeat" items="[[filteredOpenTabs_]]">
<tab-search-item id="[[item.tabId]]" data="[[item]]" <tab-search-item id="[[item.tabId]]" data="[[item]]"
on-click="onItemClick_" tabindex="-1" > on-click="onItemClick_" on-close="onItemClose_" tabindex="-1" >
</tab-search-item> </tab-search-item>
</template> </template>
</iron-selector> </iron-selector>
......
...@@ -133,6 +133,15 @@ export class TabSearchAppElement extends PolymerElement { ...@@ -133,6 +133,15 @@ export class TabSearchAppElement extends PolymerElement {
this.apiProxy_.switchToTab({tabId}); this.apiProxy_.switchToTab({tabId});
} }
/**
* @param {!Event} e
* @private
*/
onItemClose_(e) {
const tabId = Number.parseInt(e.currentTarget.id, 10);
this.apiProxy_.closeTab(tabId);
}
/** /**
* @param {number} index A valid index for an element present in the * @param {number} index A valid index for an element present in the
* filteredOpenTabs_ array. * filteredOpenTabs_ array.
...@@ -145,6 +154,7 @@ export class TabSearchAppElement extends PolymerElement { ...@@ -145,6 +154,7 @@ export class TabSearchAppElement extends PolymerElement {
} }
/** /**
* TODO(crbug.com/1113470): Tab Search item and buttons focus and navigation.
* @param {!KeyboardEvent} e * @param {!KeyboardEvent} e
* @private * @private
*/ */
......
...@@ -9,6 +9,9 @@ import {addSingletonGetter} from 'chrome://resources/js/cr.m.js'; ...@@ -9,6 +9,9 @@ import {addSingletonGetter} from 'chrome://resources/js/cr.m.js';
/** @interface */ /** @interface */
export class TabSearchApiProxy { export class TabSearchApiProxy {
/** @param {number} tabId */
closeTab(tabId) {}
/** @return {Promise<{profileTabs: tabSearch.mojom.ProfileTabs}>} */ /** @return {Promise<{profileTabs: tabSearch.mojom.ProfileTabs}>} */
getProfileTabs() {} getProfileTabs() {}
...@@ -34,6 +37,11 @@ export class TabSearchApiProxyImpl { ...@@ -34,6 +37,11 @@ export class TabSearchApiProxyImpl {
this.handler.$.bindNewPipeAndPassReceiver()); this.handler.$.bindNewPipeAndPassReceiver());
} }
/** @override */
closeTab(tabId) {
this.handler.closeTab(tabId);
}
/** @override */ /** @override */
getProfileTabs() { getProfileTabs() {
return this.handler.getProfileTabs(); return this.handler.getProfileTabs();
......
...@@ -4,15 +4,23 @@ ...@@ -4,15 +4,23 @@
--horizontal-margin: 8px; --horizontal-margin: 8px;
--vertical-margin: 12px; --vertical-margin: 12px;
align-items: center; align-items: center;
background-color: white; background-color: white;
display: flex; display: flex;
padding: var(--vertical-margin) var(--horizontal-margin); padding: var(--vertical-margin) var(--horizontal-margin);
} }
:host-context(.selected, :host:hover) { :host(:hover) {
background-color: rgba(var(--google-grey-900-rgb), 0.1); background-color: rgba(var(--google-grey-900-rgb), 0.1);
} }
:host(.selected) {
background-color: rgba(var(--google-grey-900-rgb), 0.16);
}
:host(:hover, .selected) .button-container {
display: flex;
}
.button-container { .button-container {
display: none; display: none;
} }
......
...@@ -131,6 +131,29 @@ suite('TabSearchAppTest', () => { ...@@ -131,6 +131,29 @@ suite('TabSearchAppTest', () => {
'No default selection in the precense of data'); 'No default selection in the precense of data');
}); });
test('Click on tab item triggers actions', async () => {
const tabData = {
index: 0,
tabId: 1,
favIconUrl: '',
title: 'Google',
url: 'https://www.google.com',
};
await setupTest({windows: [{active: true, tabs: [tabData]}]});
const tabSearchItem = /** @type {!HTMLElement} */
(tabSearchApp.shadowRoot.querySelector('tab-search-item'));
tabSearchItem.click();
const tabInfo = await testProxy.whenCalled('switchToTab');
assertEquals(tabData.tabId, tabInfo.tabId);
const tabSearchItemCloseButton = /** @type {!HTMLElement} */ (
tabSearchItem.shadowRoot.querySelector('cr-icon-button'));
tabSearchItemCloseButton.click();
const tabId = await testProxy.whenCalled('closeTab');
assertEquals(tabData.tabId, tabId);
});
test('Keyboard navigation on an empty list', async () => { test('Keyboard navigation on an empty list', async () => {
await setupTest({windows: [{active: true, tabs: []}]}); await setupTest({windows: [{active: true, tabs: []}]});
......
...@@ -9,6 +9,7 @@ import {TestBrowserProxy} from '../../test_browser_proxy.m.js'; ...@@ -9,6 +9,7 @@ import {TestBrowserProxy} from '../../test_browser_proxy.m.js';
export class TestTabSearchApiProxy extends TestBrowserProxy { export class TestTabSearchApiProxy extends TestBrowserProxy {
constructor() { constructor() {
super([ super([
'closeTab',
'getProfileTabs', 'getProfileTabs',
'switchToTab', 'switchToTab',
]); ]);
...@@ -24,6 +25,11 @@ export class TestTabSearchApiProxy extends TestBrowserProxy { ...@@ -24,6 +25,11 @@ export class TestTabSearchApiProxy extends TestBrowserProxy {
this.profileTabs_; this.profileTabs_;
} }
/** @override */
closeTab(tabId) {
this.methodCalled('closeTab', tabId);
}
/** @override */ /** @override */
getProfileTabs() { getProfileTabs() {
this.methodCalled('getProfileTabs'); this.methodCalled('getProfileTabs');
......
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