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

Display tooltips for buttons, especially those without text #4185

Merged
merged 2 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions ui/component/button/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Props = {
requiresAuth: ?boolean,
myref: any,
dispatch: any,
'aria-label'?: string,
};

// use forwardRef to allow consumers to pass refs to the button content if they want to
Expand Down Expand Up @@ -155,6 +156,17 @@ const Button = forwardRef<any, {}>((props: Props, ref: any) => {
}
}

// Try to generate a tooltip using available text and display it through
// the 'title' mechanism, but only if it isn't being used.
let defaultTooltip;
if (!title) {
if (props['aria-label']) {
defaultTooltip = props['aria-label'];
} else if (description) {
defaultTooltip = description;
}
}

if (requiresAuth && !emailVerified) {
return (
<NavLink
Expand All @@ -163,7 +175,7 @@ const Button = forwardRef<any, {}>((props: Props, ref: any) => {
e.stopPropagation();
}}
to={`/$/${PAGES.AUTH}?redirect=${pathname}`}
title={title}
title={title || defaultTooltip}
disabled={disabled}
className={combinedClassName}
activeClassName={activeClass}
Expand All @@ -177,7 +189,7 @@ const Button = forwardRef<any, {}>((props: Props, ref: any) => {
<NavLink
exact
to={path}
title={title}
title={title || defaultTooltip}
disabled={disabled}
onClick={e => {
e.stopPropagation();
Expand All @@ -194,7 +206,7 @@ const Button = forwardRef<any, {}>((props: Props, ref: any) => {
) : (
<button
ref={combinedRef}
title={title}
title={title || defaultTooltip}
aria-label={description || label || title}
className={combinedClassName}
onClick={e => {
Expand Down
3 changes: 3 additions & 0 deletions ui/component/header/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ const Header = (props: Props) => {
<Menu>
<MenuButton
aria-label={__('Publish a file, or create a channel')}
title={__('Publish a file, or create a channel')}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the tooltip needs to be shorter.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that sentence is fine

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a possibility that it hides other text or gets cut?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would look better if it is made "Publish Your Content!" or "Publish Freedom" or something like that. Or just "Publish Content".

This is still my personal opinion. I don't like long tooltips, they look a bit messy to me.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, they sit on top of all the other text, so it won't get hidden.

className="header__navigation-item menu__title header__navigation-item--icon"
>
<Icon size={18} icon={ICONS.PUBLISH} aria-hidden />
Expand All @@ -183,6 +184,7 @@ const Header = (props: Props) => {
<Menu>
<MenuButton
aria-label={__('Your account')}
title={__('Your account')}
className="header__navigation-item menu__title header__navigation-item--icon"
>
<Icon size={18} icon={ICONS.ACCOUNT} aria-hidden />
Expand Down Expand Up @@ -236,6 +238,7 @@ const Header = (props: Props) => {
<Menu>
<MenuButton
aria-label={__('Settings')}
title={__('Settings')}
className="header__navigation-item menu__title header__navigation-item--icon"
>
<Icon size={18} icon={ICONS.SETTINGS} aria-hidden />
Expand Down