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

Make Markdown tables accessible; fix some broken CSS #917

Closed
wants to merge 7 commits into from

Conversation

shawnbot
Copy link
Contributor

@shawnbot shawnbot commented Sep 30, 2019

This is an important update to our Markdown table element styles. The big, potentially breaking change is removing display: block, the presence of which causes accessibility tools to ignore most (all?) user-generated Markdown tables on GitHub. I've also tidied up the rest of the CSS:

  • width: 100% is out, since it works with display: table to make tables full-width (it did nothing with display: block in the mix)

  • overflow: auto is out, since it's incompatible with display: table (citation needed!)

  • tr elements don't render CSS borders, so I've removed the border declaration

  • The border declaration for td, th elements uses Primer SCSS variables. The border color will change from (aligned vertically for easy comparison):

    • #dfe2e5 (lighten($gray-300, 5%)) to
    • #d1d5da ($border-gray-dark$gray-300)
  • Cell padding is now ($spacer-2 - 2) ($spacer-3 - 2), which computes to 6px 14px rather than the previous (static) 6px 13px. Maybe it's time to rip off the band-aid and just make this $spacer-2 $spacer-3?? 🤷‍♂

Since visually this may be a breaking change, I'm queueing it up for our 14.0.0 release (no PR yet).

Fixes #924.

@vercel
Copy link

vercel bot commented Sep 30, 2019

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/primer/primer-css/laar6wjec
🌍 Preview: https://primer-css-git-markdown-table-refactor.primer.now.sh

@shawnbot shawnbot mentioned this pull request Oct 1, 2019
19 tasks
@shawnbot
Copy link
Contributor Author

shawnbot commented Oct 1, 2019

I just noticed that we use the equivalent of $spacer-2 $spacer-3 in Doctocat. So maybe it's safe to do so here, too? Also, @colebemis we're probably going to want to propagate these changes back to Doctocat. 😁

@shawnbot shawnbot changed the title Markdown table refactor Make Markdown tables accessible; fix some broken CSS Oct 1, 2019
src/markdown/tables.scss Outdated Show resolved Hide resolved
Copy link
Contributor

@simurai simurai left a comment

Choose a reason for hiding this comment

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

This looks good. Just added some comments with potentially making changes to the border and padding.

width: 100% is out, since it works with display: table to make tables full-width (it did nothing with display: block in the mix)

Tested removing display: block; + width: 100%; in Chrome DevTools and no visual change is noticeable. So seems fine to remove. 🤷‍♂ Curious about the initial reason? Maybe it was added for a certain browser?

Cell padding is now ($spacer-2 - 2) ($spacer-3 - 2), which computes to 6px 14px rather than the previous (static) 6px 13px. Maybe it's time to rip off the band-aid and just make this $spacer-2 $spacer-3?? 🤷‍♂

Or just $spacer-2? Then a bit more columns would fit.

src/markdown/tables.scss Show resolved Hide resolved
src/markdown/tables.scss Outdated Show resolved Hide resolved
src/markdown/tables.scss Show resolved Hide resolved
Copy link
Contributor

@simurai simurai left a comment

Choose a reason for hiding this comment

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

Ohhh.. wait.. it looks like removing display: block; + width: 100%; makes the overflow: auto; not work when there are long strings without white space. Like in this example:

Before After
asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf

Screen Shot 2019-10-04 at 6 02 27 PM

We could use word-break: break-word; or table-layout: fixed;. But that could also make it harder to read a table with long strings because they would wrap and create big cells. Maybe there is another way to force scrolling? Like render an extra wrapper that scrolls the table:

<div style="overflow-x: auto">
  <table>

@shawnbot
Copy link
Contributor Author

shawnbot commented Oct 7, 2019

Ah yes, overflow... This would definitely be a breaking change, huh? 😬

I noticed that .comment-body gets overflow: visible on github.com, which seems... not quite right to me? But that's probably so that popovers (edit: tooltips!) work properly.

We might need to hold off on this until we've sorted out our z-index situation. ☹️

@shawnbot
Copy link
Contributor Author

shawnbot commented Nov 5, 2019

@simurai after some investigation, it looks to me like we can only solve the overflow problem by:

  1. Wrapping each table in a div with the overflow-x-auto class;
  2. Adding overflow-x: auto to the .markdown-body styles; or
  3. Selectively adding the overflow-x-auto class to every instance of markdown-body.

I'm looking into how feasible 1) is, given our... complicated array of markdown filters in dot-com. 2) and 3) would be "easier", but both carry a lot of risk and will almost certainly break existing tooltips and/or popovers.

@vercel vercel bot temporarily deployed to staging November 5, 2019 22:37 Inactive
src/markdown/tables.scss Outdated Show resolved Hide resolved
@shawnbot
Copy link
Contributor Author

shawnbot commented Nov 5, 2019

If anyone comes across this and wants to help test out weird edge cases in the wild, you can do it by pasting the following into your browser's JavaScript console:

// insert style overrides 
const style = document.createElement('style')
style.textContent = `.markdown-body table {
  display: table !important;
  width: auto !important;
}`
document.head.appendChild(style)

// wrap every markdown table in <div class="overflow-x-auto">
for (const table of document.querySelectorAll('.markdown-body table')) {
  const div = document.createElement('div')
  div.className = 'overflow-x-auto'
  table.parentNode.insertBefore(div, table)
  div.appendChild(table)
}

@simurai
Copy link
Contributor

simurai commented Nov 6, 2019

  1. Wrapping each table in a div with the overflow-x-auto class;

I think this will break the :last-child selector and add extra bottom margin if the table is last:

Screen Shot 2019-11-06 at 10 18 54 AM

We could add mb-3 to the wrapper and remove table from here

. But that only works for github/github and would break for all the other "Markdown to HTML" libraries. Is that a concern?

@shawnbot
Copy link
Contributor Author

shawnbot commented Nov 6, 2019

@simurai good catch. One fix for that could be to change the > *:last-child selector to > *:last-child, > *:last-child > table.

@simurai simurai changed the base branch from release-14.0.0 to master November 26, 2019 07:38
@simurai
Copy link
Contributor

simurai commented Apr 13, 2020

Closing as wontfix, see #924 (comment).

There is still "Convert markdown page to one big example" #1065 that got cherry picked to improve the docs.

@simurai simurai closed this Apr 13, 2020
@simurai simurai deleted the markdown-table-refactor branch April 13, 2020 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Markdown tables are inaccessible
4 participants