Commit 7b8c6a79 authored by Omid Tourzan's avatar Omid Tourzan Committed by Commit Bot

[files-tooltip] Add padding to the tooltips on the edge.

Adding 6px padding to the tooltip if it's on the edge of the window.

Adjusting current calculation to consider 6px padding according to the
ux spec.

Tested on rtl successfully as well.

Bug: 1108152
Change-Id: Icdc3d59983e75a397dd6a0971ea22d95dc82d8e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2318954
Commit-Queue: Omid Tourzan <oto@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792103}
parent b55ffd67
...@@ -171,6 +171,8 @@ const FilesTooltip = Polymer({ ...@@ -171,6 +171,8 @@ const FilesTooltip = Polymer({
const useCardTooltip = target.hasAttribute('show-card-tooltip'); const useCardTooltip = target.hasAttribute('show-card-tooltip');
const windowEdgePadding = 6;
const label = target.getAttribute('aria-label'); const label = target.getAttribute('aria-label');
if (!label) { if (!label) {
return; return;
...@@ -222,11 +224,14 @@ const FilesTooltip = Polymer({ ...@@ -222,11 +224,14 @@ const FilesTooltip = Polymer({
this.cleanupCardTooltip_(); this.cleanupCardTooltip_();
left = rect.left + rect.width / 2 - this.offsetWidth / 2; left = rect.left + rect.width / 2 - this.offsetWidth / 2;
if (left < 0) { if (left < windowEdgePadding) {
left = 0; left = windowEdgePadding;
} }
if (left > document.body.offsetWidth - this.offsetWidth) {
left = document.body.offsetWidth - this.offsetWidth; const maxLeft =
document.body.offsetWidth - this.offsetWidth - windowEdgePadding;
if (left > maxLeft) {
left = maxLeft;
} }
} }
......
...@@ -55,6 +55,8 @@ const bodyContent = ` ...@@ -55,6 +55,8 @@ const bodyContent = `
<files-tooltip></files-tooltip> <files-tooltip></files-tooltip>
`; `;
const windowEdgePadding = 6;
function setUp() { function setUp() {
/** @const {boolean} Assume files-ng in unittest. */ /** @const {boolean} Assume files-ng in unittest. */
const enableFilesNg = true; const enableFilesNg = true;
...@@ -108,7 +110,7 @@ function testFocus(callback) { ...@@ -108,7 +110,7 @@ function testFocus(callback) {
assertEquals('Chocolate!', label.textContent.trim()); assertEquals('Chocolate!', label.textContent.trim());
assertTrue(tooltip.hasAttribute('visible')); assertTrue(tooltip.hasAttribute('visible'));
assertEquals('4px', tooltip.style.left); assertEquals('6px', tooltip.style.left);
if (window.isFilesNg()) { if (window.isFilesNg()) {
assertEquals('78px', tooltip.style.top); assertEquals('78px', tooltip.style.top);
...@@ -124,8 +126,8 @@ function testFocus(callback) { ...@@ -124,8 +126,8 @@ function testFocus(callback) {
assertEquals('Cherries!', label.textContent.trim()); assertEquals('Cherries!', label.textContent.trim());
assertTrue(tooltip.hasAttribute('visible')); assertTrue(tooltip.hasAttribute('visible'));
const expectedLeft = const expectedLeft = document.body.offsetWidth -
document.body.offsetWidth - tooltip.offsetWidth + 'px'; tooltip.offsetWidth - windowEdgePadding + 'px';
assertEquals(expectedLeft, tooltip.style.left); assertEquals(expectedLeft, tooltip.style.left);
if (window.isFilesNg()) { if (window.isFilesNg()) {
...@@ -154,7 +156,7 @@ function testHover(callback) { ...@@ -154,7 +156,7 @@ function testHover(callback) {
assertTrue(tooltip.hasAttribute('visible')); assertTrue(tooltip.hasAttribute('visible'));
assertEquals(tooltip.getAttribute('aria-hidden'), 'false'); assertEquals(tooltip.getAttribute('aria-hidden'), 'false');
assertEquals('4px', tooltip.style.left); assertEquals('6px', tooltip.style.left);
if (window.isFilesNg()) { if (window.isFilesNg()) {
assertEquals('78px', tooltip.style.top); assertEquals('78px', tooltip.style.top);
} else { } else {
...@@ -170,8 +172,8 @@ function testHover(callback) { ...@@ -170,8 +172,8 @@ function testHover(callback) {
assertEquals('Cherries!', label.textContent.trim()); assertEquals('Cherries!', label.textContent.trim());
assertTrue(tooltip.hasAttribute('visible')); assertTrue(tooltip.hasAttribute('visible'));
const expectedLeft = const expectedLeft = document.body.offsetWidth -
document.body.offsetWidth - tooltip.offsetWidth + 'px'; tooltip.offsetWidth - windowEdgePadding + 'px';
assertEquals(expectedLeft, tooltip.style.left); assertEquals(expectedLeft, tooltip.style.left);
if (window.isFilesNg()) { if (window.isFilesNg()) {
......
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