Skip to content

Fix sticky file header tooltips#1581

Merged
sindresorhus merged 14 commits into
refined-github:masterfrom
wsmd:fix-sticky-file-header-tooltips
Nov 6, 2018
Merged

Fix sticky file header tooltips#1581
sindresorhus merged 14 commits into
refined-github:masterfrom
wsmd:fix-sticky-file-header-tooltips

Conversation

@wsmd
Copy link
Copy Markdown
Contributor

@wsmd wsmd commented Oct 13, 2018

There's a minor issue causing tooltips of elements in the sticky file header (.file-header) to be cut-off. This happens because of the sticky position that Refined Github applies to the header.

A single file

screen shot 2018-10-13 at 5 18 51 pm

Pull Request files

screen shot 2018-10-13 at 5 20 02 pm

Solution

This PR attempts to resolve the issue by adding a workaround that reverses the direction of the tooltips. This only applies to:

  • A single file page
  • Pull Requests files page

https://github.com/sindresorhus/refined-github/blob/f8abd1e5d7c9d3b45bf3f49e58244e01b22938ca/source/content.css#L666-L668

https://github.com/sindresorhus/refined-github/blob/f8abd1e5d7c9d3b45bf3f49e58244e01b22938ca/source/content.css#L673-L675

After

screen shot 2018-10-13 at 5 24 01 pm

screen shot 2018-10-13 at 5 23 32 pm


Closes #1295 (also see: #1308, #689)

Comment thread source/content.js Outdated
}

if (pageDetect.isSingleFile() || pageDetect.isPRFiles()) {
enableFeature(fixStickyFileHeaderTooltips);
Copy link
Copy Markdown
Contributor Author

@wsmd wsmd Oct 13, 2018

Choose a reason for hiding this comment

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

I'm not sure if this the right place to call this script, or even if the script should be added to /features, because this isn't necessarily a "feature", but rather a fix for another feature – the sticky file-header, that is. Any thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's right, I think if this PR gets accepted, it will have to becomes its own feature: sticky-file-headers or even just sticky-headers that injects the CSS

https://github.com/sindresorhus/refined-github/blob/f8abd1e5d7c9d3b45bf3f49e58244e01b22938ca/source/content.css#L666-L668

and also fixes the issues it causes.

That, as previously mentioned, only if it's too much trouble to fix with CSS alone, which would be preferable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That, as previously mentioned, only if it's too much trouble to fix with CSS alone, which would be preferable.

This is very interesting! I can't think of any way to get around this issue with CSS alone, and if there is a way to do it, I don't think it would be as straightforward as the JS approach of flipping the tooltip class names from "north" to "south".

What I don't like about this PR so far is the fact that the current implementation/script fix-sticky-file-header-tooltips isn't a feature!

I think if this PR gets accepted, it will have to become its own feature: sticky-file-headers or even just sticky-headers that injects the CSS

I very much like the idea of encapsulating everything about the sticky headers to its own feature! Thanks for suggesting it! 🙇

That said, a feature like that requires CSS. The challenge here is that: A) currently all CSS live in one place, and B) there is no easy way to tie CSS to the script of a specific feature.

Having something like that is not a very bad idea, IMO! I have given this some thoughts, and I have some ideas that I'd like to share in a separate issue outside this PR since this conversation could apply to any feature, not just this one.

const oppositeDirections = {
'tooltipped-n': 'tooltipped-s',
'tooltipped-ne': 'tooltipped-se',
'tooltipped-nw': 'tooltipped-sw'
Copy link
Copy Markdown
Contributor Author

@wsmd wsmd Oct 13, 2018

Choose a reason for hiding this comment

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

@wsmd
Copy link
Copy Markdown
Contributor Author

wsmd commented Oct 13, 2018

I also noticed that some related tooltips were intentionally removed (#689 (comment), #799, #1234) to get around this issue. Could we use this workaround/idea instead, and restore some of those tooltips?

Proof of concept:

https://github.com/sindresorhus/refined-github/blob/f8abd1e5d7c9d3b45bf3f49e58244e01b22938ca/source/content.css#L36-L39

  [aria-label='Edit comment']::after,
- [aria-label='Open this file in GitHub Desktop']::before,
- [aria-label='Open this file in GitHub Desktop']::after,
  [aria-label$='branch to make changes.']::before,

screen shot 2018-10-13 at 6 18 10 pm


export default function () {
for (const el of select.all('.file-header [class*=tooltipped-n]')) {
let direction;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lo-fi one-liner to replace everything in this loop

el.className = el.className.replace('tooltipped-n', 'tooltipped-s');

Copy link
Copy Markdown
Contributor Author

@wsmd wsmd Oct 14, 2018

Choose a reason for hiding this comment

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

I like how explicit the current implementation is, but I understand that it might be a bit too verbose. 👍

I'll replace it with your suggestion, and probably add some comments for future maintainers to explain what it's exactly doing and emphasizing that we're replacing all north directions, not just "n" to "s", especially that, at a glance, el.className.replace looks very close to el.classList.replace but it behaves very differently.

Comment thread source/content.css
[aria-label='Open this file in GitHub Desktop']::before,
[aria-label='Open this file in GitHub Desktop']::after,
[aria-label$='branch to make changes.']::before,
[aria-label$='branch to make changes.']::after,
Copy link
Copy Markdown
Contributor Author

@wsmd wsmd Oct 14, 2018

Choose a reason for hiding this comment

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

Since I got a thumbs up from @bfred-it on #1581 (comment), I went ahead and reverted all existing overrides that were hiding the tooltips.

Tooltips should look like this now 🎉

screen shot 2018-10-13 at 11 48 55 pm
screen shot 2018-10-13 at 11 51 43 pm
screen shot 2018-10-13 at 11 51 50 pm
screen shot 2018-10-13 at 11 52 08 pm
screen shot 2018-10-13 at 11 52 25 pm

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The last two can still be hidden. The tool tips don’t add any more information and the icons are obvious.

Copy link
Copy Markdown
Contributor Author

@wsmd wsmd Oct 14, 2018

Choose a reason for hiding this comment

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

The last two can still be hidden.

I agree 👌. While most of the tooltips listed there (now removed) were added because of this specific issue within file-header, some other tooltips, like the notification indicator for example, can be redundant.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All of these selectors should be restored, the icons are self-explanatory:

[aria-label^='View the whole file']::before,
[aria-label^='View the whole file']::after,
[aria-label^='Change this file']::before,
[aria-label^='Change this file']::after,
[aria-label='Delete this file']::before,
[aria-label='Delete this file']::after,
[aria-label='Edit this file']::before,
[aria-label='Edit this file']::after,

@fregante
Copy link
Copy Markdown
Member

fregante commented Oct 15, 2018

A couple of things I'd rather see:

  • document.documentElement.classList.add('rgh-sticky-header') instead of selecting all elements manually (which wouldn't work on files that load later on big diffs)
  • use select.all('.file-header [class*=tooltipped-n], .table-list-header [class*=tooltipped-n]') in the main loop

@wsmd
Copy link
Copy Markdown
Contributor Author

wsmd commented Oct 15, 2018

oooh absolutely! good catch on the first point!

I'll also rename the sticky-file-header to make-headers-sticky for consistency with make-discussion-sidebar-sticky. This feature is also for search headers, not just file headers. Let me know what you think.

@fregante
Copy link
Copy Markdown
Member

Better yet... this whole feature can be left in the CSS by just overriding the position via CSS:

.file-header [class*=tooltipped-n]:before,
.table-list-header [class*=tooltipped-n]:before { 
    top: auto !important;
    bottom: -5px !important;
    transform: rotate(180deg)
}

.file-header [class*=tooltipped-n]:after,
.table-list-header [class*=tooltipped-n]:after { 
    top: 100% !important;
    bottom: auto  !important;
    margin-top: 5px  !important;
}

@wsmd
Copy link
Copy Markdown
Contributor Author

wsmd commented Oct 15, 2018

Aside from making this whole a thing its own feature, which isn't a bad idea. I'm curious, why do you think that approach ☝️ is better than the following?

for (const el of select.all('.file-header [class*=tooltipped-n]')) {
  el.className = el.className.replace('tooltipped-n', 'tooltipped-s');
}

I feel like renaming tooltipped-n* to tooltipped-s* is likely to be future proof. If Github decides to change a tiny bit of their CSS, this extension has to be updated if we went with manually hard coding CSS properties. The style for that already exists.. it's tooltipped-s*, why should we replicate it?

Comment thread source/content.js Outdated
pageDetect.isPRSearch() ||
pageDetect.isSingleFile()
) {
enableFeature(makeHeadersSticky);
Copy link
Copy Markdown
Contributor Author

@wsmd wsmd Oct 15, 2018

Choose a reason for hiding this comment

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

I'll move this to the top of ajaxedPagesHandler since the original styles were applied globally anyways. I don't think there's a need to limit this to certain pages.

@fregante
Copy link
Copy Markdown
Member

If Github decides to change a tiny of their CSS

That's indeed a problem, but that also applies to JavaScript code and that usually requires more work to fix anyway.

The CSS-only solution is indeed "dirtier" (like my earlier suggestion to use className.replace) but perhaps we can agree that it's more efficient: it works across the board wherever those selectors apply, which means they also work on ajaxed-in files without further effort.

That said, the latest iteration of your PR seems rather lean so let's see what others say.

@wsmd
Copy link
Copy Markdown
Contributor Author

wsmd commented Oct 15, 2018

Cool! I don't necessarily disagree with any of that. Like you said, the CSS solution does feel a bit dirtier (idk, all those !important feel a bit overwhelming haha).

I'm very happy with how this PR has turned out! Thanks a lot for the help! :)

I look forward to others feedback as well!

Copy link
Copy Markdown
Member

@fregante fregante left a comment

Choose a reason for hiding this comment

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

After this change it can be merged.

Comment thread source/content.css
[aria-label='Open this file in GitHub Desktop']::before,
[aria-label='Open this file in GitHub Desktop']::after,
[aria-label$='branch to make changes.']::before,
[aria-label$='branch to make changes.']::after,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All of these selectors should be restored, the icons are self-explanatory:

[aria-label^='View the whole file']::before,
[aria-label^='View the whole file']::after,
[aria-label^='Change this file']::before,
[aria-label^='Change this file']::after,
[aria-label='Delete this file']::before,
[aria-label='Delete this file']::after,
[aria-label='Edit this file']::before,
[aria-label='Edit this file']::after,

@sindresorhus sindresorhus merged commit a9ec680 into refined-github:master Nov 6, 2018
@sindresorhus
Copy link
Copy Markdown
Member

Thanks for fixing, @wsmd :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Markdown rich diff tooltip appears underneath diff settings bar

3 participants