Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview AMP tooltip displays incorrectly in editor #4590

Closed
ernee opened this issue Apr 15, 2020 · 15 comments · Fixed by #4601
Closed

Preview AMP tooltip displays incorrectly in editor #4590

ernee opened this issue Apr 15, 2020 · 15 comments · Fixed by #4601
Assignees
Labels
Bug Something isn't working Editor
Milestone

Comments

@ernee
Copy link

ernee commented Apr 15, 2020

Bug Description

In the editor, the tooltip to Preview AMP displays incorrectly (hidden behind another element).

Expected Behaviour

The tooltip should be fully visible.

Steps to reproduce

  1. Edit a post or page (using WordPress Core or Gutenberg plugin)
  2. Hover over the AMP preview icon at the top right
  3. See the Preview AMP tool tip display incorrectly (hidden)

Screenshots

WordPress Core

tooltip in WP Core

Gutenberg plugin

tooltip in Gutenberg plugin

Additional context

  • WordPress version: 5.4
  • Plugin version: 1.5.3
  • Gutenberg plugin version (if applicable): 7.9.0
  • AMP plugin template mode: Transitional, Reader
  • PHP version: 7.3.5
  • OS: MacOS
  • Browser: Chrome
  • Device: MacBook Air

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation brief

QA testing instructions

Demo

Changelog entry

@westonruter westonruter added Bug Something isn't working Editor labels Apr 15, 2020
@kienstra
Copy link
Contributor

Hi @ernee!
Hope you've been doing great!

Yeah, this is definitely an issue. In my local, the tooltip is cut off below:

tooltip-here

I'll work on this.

@kienstra
Copy link
Contributor

If it's alright, I'll come back to this tomorrow.

There doesn't look to be a quick fix, though I'm not good at CSS.

For example, simply changing the z-index or position of the <Popover> in the <Tooltip> didn't fix this.

@westonruter
Copy link
Member

It appears the Tooltip component can't be nested inside that button in the DOM. No amount of z-index will help apparently. The element containing the tooltip that appears for the Settings icon is located elsewhere in the DOM somehow.

@kienstra
Copy link
Contributor

Yeah, there might not be a way to keep the tooltip.

@westonruter
Copy link
Member

I'd look into how the Setting button has integrated the tooltip in Gutenberg.

@kienstra
Copy link
Contributor

kienstra commented Apr 16, 2020

1. Tooltip might not be feasible

Hi @westonruter,
Sorry for the delay.

I couldn't find a way to prevent the <Tooltip> from being cut off. The problem looks to be that tooltips need to be further away in the DOM.

But this button is rendered into a single element in the DOM, and that element isn't aware of the block editor's React components. It's rendered like this because there wasn't a Slot/Fill or filter to render it properly.

So the tooltip renders inside the Button, and looks bad.

For example, with the 'Preview AMP' button, the tooltip is inside the button:

amp-closepi

But for the 'More tools & options' button, which looks good, the tooltip is pretty far away from the button in the DOM:

tooltip-button-

@kienstra
Copy link
Contributor

kienstra commented Apr 16, 2020

2. Suggestion

What do you think about simply removing the <Tooltip>?

diff --git a/assets/src/block-editor/components/amp-preview.js b/assets/src/block-editor/components/amp-preview.js
index dfbace46e..ed8a4fa1e 100644
--- a/assets/src/block-editor/components/amp-preview.js
+++ b/assets/src/block-editor/components/amp-preview.js
@@ -236,25 +236,22 @@ class AMPPreview extends Component {
 
                return (
                        isEnabled && ! errorMessages.length && ! isStandardMode && (
-                               <Tooltip text={ __( 'Preview AMP', 'amp' ) } >
-                                       <Button
-                                               className="amp-editor-post-preview"
-                                               href={ href }
-                                               label={ __( 'Preview AMP', 'amp' ) }
-                                               isSecondary
-                                               disabled={ ! isSaveable }
-                                               onClick={ this.openPreviewWindow }
-                                               ref={ this.buttonRef }
-                                       >
-                                               { ampFilledIcon( { viewBox: '0 0 62 62', width: 18, height: 18 } ) }
-                                               <span className="screen-reader-text">
-                                                       {
-                                                       
        /* translators: accessibility text */
-                                                       
        __( '(opens in a new tab)', 'amp' )
-                                                       }
-                                               </span>
-                                       </Button>
-                               </Tooltip>
+                               <Button
+                                       className="amp-editor-post-preview"
+                                       href={ href }
+                                       isSecondary
+                                       disabled={ ! isSaveable }
+                                       onClick={ this.openPreviewWindow }
+                                       ref={ this.buttonRef }
+                               >
+                                       { ampFilledIcon( { viewBox: '0 0 62 62', width: 18, height: 18 } ) }
+                                       <span className="screen-reader-text">
+                                               {
+                                                       /* translators: accessibility text */
+                                                       __( '(opens in a new tab)', 'amp' )
+                                               }
+                                       </span>
+                               </Button>
                        )
                );
        }

That's probably not great for usability.

But there's screen reader text inside the Button.

And the documentation for Button says:

All button types use text labels to describe the action that happens when a user taps a button. If there’s no text label, there should be an icon to signify what the button does (e.g. an IconButton component).

...and this does have an icon.

@westonruter
Copy link
Member

There's a difference between the Settings button and the AMP Preview button in terms of the React components.

With React Dev Tools this is what the Settings tooltip looks like when it is open:

image

Compare with the AMP Preview button:

image

We're missing a Fill construct here.

Nevertheless, the “Settings“ button doesn't show a Tooltip being used here (source):

				<Button
					icon={ cog }
					label={ __( 'Settings' ) }
					onClick={ toggleGeneralSidebar }
					isPressed={ isEditorSidebarOpened }
					aria-expanded={ isEditorSidebarOpened }
					shortcut={ shortcut }
				/>

I'm not sure how the tooltip is being wired up for the Settings element, but it's being done differently than the AMP Preview button. I suspect that changing the tooltip to be added in the same way will fix the issue with the positioning.

@kienstra
Copy link
Contributor

kienstra commented Apr 16, 2020

Hi Weston,
Thanks for your ideas. I tested something like you suggested, but I'll try it again.

The 'Settings' button has a Popover via its label prop. It renders a Tooltip using that label prop passed to it.

Then, the <Tooltip> renders <Fill>. I don't think there's a Slot that the fill can use, because this 'Preview AMP' button is rendered into a single DOM element, and doesn't have access to any of the block editor.

@kienstra
Copy link
Contributor

Here's something pretty similar to the Settings button, and the tooltip is still covered.

tooltip

diff --git a/assets/src/block-editor/components/amp-preview.js b/assets/src/block-editor/components/amp-preview.js
index dfbace46e..3b28af0e0 100644
--- a/assets/src/block-editor/components/amp-preview.js
+++ b/assets/src/block-editor/components/amp-preview.js
@@ -236,25 +236,17 @@ class AMPPreview extends Component {
 
                return (
                        isEnabled && ! errorMessages.length && ! isStandardMode && (
-                               <Tooltip text={ __( 'Preview AMP', 'amp' ) } >
-                                       <Button
-                                               className="amp-editor-post-preview"
-                                               href={ href }
-                                               label={ __( 'Preview AMP', 'amp' ) }
-                                               isSecondary
-                                               disabled={ ! isSaveable }
-                                               onClick={ this.openPreviewWindow }
-                                               ref={ this.buttonRef }
-                                       >
-                                               { ampFilledIcon( { viewBox: '0 0 62 62', width: 18, height: 18 } ) }
-                                               <span className="screen-reader-text">
-                                                       {
-                                                       
        /* translators: accessibility text */
-                                                       
        __( '(opens in a new tab)', 'amp' )
-                                                       }
-                                               </span>
-                                       </Button>
-                               </Tooltip>
+                               <Button
+                                       icon={ ampFilledIcon( { viewBox: '0 0 62 62', width: 18, height: 18 } ) }
+                                       label={ __( 'Preview AMP', 'amp' ) }
+                                       className="amp-editor-post-preview"
+                                       href={ href }
+                                       label={ __( 'Preview AMP', 'amp' ) }
+                                       isSecondary
+                                       disabled={ ! isSaveable }
+                                       onClick={ this.openPreviewWindow }
+                                       ref={ this.buttonRef }
+                               />
                        )
                );
        }

@westonruter
Copy link
Member

OK, how about just using a classic title attribute instead?

@kienstra
Copy link
Contributor

Good idea, that works locally.

@amedina
Copy link
Member

amedina commented May 19, 2020

The tooltip is showing properly, but the styling of the buttons changed. The way they were styled before looked better (see screenshots at the beginning of this issue; and see attachments in this comment). Now the Preview and the AMP Preview look disconnected.

Screen Shot 2020-05-18 at 5 28 51 PM
Screen Shot 2020-05-18 at 5 28 44 PM

@westonruter
Copy link
Member

@amedina this is expected. The button is required to be disconnected in current versions of Gutenberg because the Preview dropdown component is not extendable.

@amedina
Copy link
Member

amedina commented May 19, 2020

I see. It looks weird disconnected because the semantics of the AMP symbol is not conveyed as clearly.

Let's ship it and we will revise during UX review.

@kmyram kmyram added this to the v1.5.4 milestone May 27, 2020
@kmyram kmyram closed this as completed Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Editor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants