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

Href for table rows #6223

Open
sassanh opened this issue Dec 12, 2020 · 8 comments
Open

Href for table rows #6223

sassanh opened this issue Dec 12, 2020 · 8 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: table

Comments

@sassanh
Copy link

sassanh commented Dec 12, 2020

I cannot find a way to render a table row that is actually a link too. This is possible to write something like this:

<table>
  <tbody>
    <a style='display: table-row;'>
      <td>
        Some text
      </td>
    </a>
  </tbody>
</table>

But as far as I understand it will make things hard for accessibility tools and may break some of them.
One solution that comes to my mind is to provide the ability to set an href property for tr (and maybe td) elements and converting them to anchor rows, but it may break many defaults or assumptions. So I would like to discuss it here.

@Yay295
Copy link
Contributor

Yay295 commented Dec 12, 2020

You could use JavaScript. Is there a reason you need an entire row to be a link though? Why not have just one of the cells contain a link? Do you even need to be using a table for what you're doing?

@sassanh
Copy link
Author

sassanh commented Dec 12, 2020

Using javascript is not the best idea, if one uses javascript for this purpose he should try to take care of all the different ways an anchor link is dealt in different operating systems/browsers/assistive tools, some of them being impossible to simulate. For example even if I take care of the behavior of different mouse buttons and keyboard modifier combinations (middle clicking, cmd + left click, ctrl + left click in another os, cmd + option + shift, etc) I still can't provide the "copy link", "open link in new tab" or "add link to bookmarks" items in the context menu of an anchor rendered by the browser, I'm sure there are many other details I cannot completely simulate with JS.
In HTML I can wrap any block inside an anchor and make it a native anchor link, except some particular elements, one of them is tr element, I think HTML would be a better markup language if we can get rid of these exceptions unless we have a good reason for these exceptions.

@sassanh
Copy link
Author

sassanh commented Dec 12, 2020

An alternative just came to my mind is to partially ignore an anchor when used between a tbody and a tr (do not render it and just use its anchor behavior.) Just an idea.

@annevk
Copy link
Member

annevk commented Dec 14, 2020

See https://github.com/whatwg/html/blob/master/FAQ.md#html-should-support-href-on-any-element. This indeed doesn't give you native UI for the entire row and it would be nice to offer that, but it's basically too much added complexity for a minor win. (We also cannot really change the HTML parser so that's not a viable route.)

@sassanh
Copy link
Author

sassanh commented Dec 14, 2020

Thanks @annevk! Now I understand it better why this is not supported for any element and I wonder if it is also too complex to add href only for tr elements? And maybe tbody, thead, tfoot, th and td elements in the future, I think these other table components have lower priority than tr.

I try hard to avoid hacks in the products I build and simulating anchors with javascript looks like a terrible hack. I think we all agree that it introduces inconvenience for the end user when she right clicks on a tr and doesn't see desired actions she would expect in the context menu of an anchor, or the plugins/tools she installed on her machine/browser don't work well with simulated linked table rows, or when a person with some disability can't open table rows in a new tab because of this problem, I think resolving these issues is not a "minor win" (put aside the inconvenience of the developers when they have to provide this particular anchors with a different approach.)

I'm not looking forward to see this implemented in major browsers in the next year, maybe it has lower priority than other concurrent issues, but I'm looking forward to see the community including people behind major browsers acknowledge this is an issue and needs to be resolved (maybe in 10 years or even unknown future.)

@annevk
Copy link
Member

annevk commented Dec 14, 2020

The suggested solution is accessible as the actual link would be present in the first cell of the row. I'm personally happy to leave this open to see if such interest materializes, but I wouldn't bet on it.

@annevk annevk added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: table labels Dec 14, 2020
@croraf
Copy link

croraf commented Oct 20, 2023

The suggestion in https://github.com/whatwg/html/blob/master/FAQ.md#html-should-support-href-on-any-element for tr case is just silly. We need this feature.

Is adding href support to tr not feasible?

It would:

  • show target link when hovered at the bottom of the browser
  • show navigation options when right clicked
  • allow ctrl/shift + click behavior
  • allow keyboard focus
  • (optionally) add cursor pointer

I mean just check the number of likes here: https://stackoverflow.com/questions/17147821/how-to-make-a-whole-row-in-a-table-clickable-as-a-link

@annevk
Copy link
Member

annevk commented Oct 20, 2023

@croraf please adhere to https://whatwg.org/code-of-conduct. Instead of silly, try inadequate (and as noted above, we know, but solving it is non-trivial).

I wonder if an alternative solution here could be through CSS. Some kind of feature that allows elements to retarget user interaction. Might be too much of a boon for clickjackers though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: table
Development

No branches or pull requests

4 participants