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

Improve EuiBasicTable caption #2782

Merged
merged 11 commits into from
Jan 29, 2020

Conversation

andreadelrio
Copy link
Contributor

@andreadelrio andreadelrio commented Jan 22, 2020

Fixes #2336

Summary

Improve EuiBasicTable caption to include the number of total rows when there's multiple pages.

Previous caption

  • Below is a table of {itemCount} items.

New caption

  • Below is a table containing {itemCount} rows. [There's only 1 page]
  • Below is a table containing {itemCount} rows out of {totalItemCount}. [When there's more than 1 page]

Not sure what to do in the case shown below. Currently the caption for this table would be Below is a table containing 0 rows. Should we be doing something like Below is a table containing no data instead? @myasonik what do you think?

image

Fixes #2336

Checklist

- [ ] Check against all themes for compatibility in both light and dark modes
- [ ] Checked in mobile
- [ ] Checked in IE11 and Firefox
- [ ] Props have proper autodocs
- [ ] Added documentation examples

  • Added or updated jest tests
    - [ ] Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@myasonik
Copy link
Contributor

myasonik commented Jan 22, 2020

Sorry time chime in only after you've put some time into this but, honestly, I'm not sure if there's much/any value in this sort of caption.

Screen readers already have robust table navigation capabilities so describing the size of the table is usually already done natively. (This isn't the case for paginated tables but that requires a different solution outside of captions.)

Also, this quickly breaks down when you have multiple tables on a page because the caption gives you no context for what's in it.

I think the most useful default caption would be to list the column titles. Maybe something like This table contains info on: <column titles>? This avoids the syntax problem of below and provides more context as a title than the number of rows. (Yes, users can find out column headers natively, same as the can find out the number of rows, but I think that a list of column headers is a better "name" for a table than the number of rows it contains.)

But captions need to be overridable by implementing developers because the best captions will always usually be user supplied (until we can run sentiment analysis on tables). (For your example table here, something like Table of user data is more to the point than listing every column title.)

@snide
Copy link
Contributor

snide commented Jan 22, 2020

@myasonik Can you distill that into what you'd like to see here? Specifically I agree that this is likely best served by the consuming engineer. My suggestion would be to:

  1. Make the caption configurable, with the default left as @andreadelrio has it (i don't think putting a list of column names does much (not to mention unwieldy), and is better served by Improve accessibility of EuiTableRowCell #2335 which we can attack separately).
  2. Put a docs note suggesting setting caption is important and people should use it!
  3. Remove the aria/role bits on caption as you suggest.

That's a decent first step that allows folks to fix #2336 throughout Kibana, then we can consider this (and a couple other a11y required props) later in a holistic a11y breaking changes release in the future.

@myasonik
Copy link
Contributor

myasonik commented Jan 22, 2020

I agree with 2 and 3 in your list.

I think maybe an example will better explain why I prefer a list of column headers over a count of rows:

Think of the <caption> more as a "name" for table. (I know it sounds incorrect but it's more closely what it acts like.) Which makes more sense for me to say:

  1. "Hey, will you take a look at that table which has 6 rows?"
  2. "Hey, will you take a look at that table which tells me the First Name, Last Name, Date of Birth, and Nationality?"

Option 1 is what EUI currently has. Option 2 is what I'm proposing. It's longer, for sure, but between those options, I think Option 2 is more clear.

#2335 which you mention tackles a different problem all together.

@myasonik
Copy link
Contributor

You also mention adding this to a future breaking change. Is that to suggest that we force consuming engineers to provide a caption?

(I would be for that if that's what you're suggesting.)

@snide
Copy link
Contributor

snide commented Jan 22, 2020

You also mention adding this to a future breaking change. Is that to suggest that we force consuming engineers to provide a caption?

(I would be for that if that's what you're suggesting.)

Correct. Ultimately, that's the real way to solve this one. This first phase just unblocks folks quickly.

@andreadelrio
Copy link
Contributor Author

  1. Make the caption configurable, with the default left as @andreadelrio has it (i don't think putting a list of column names does much (not to mention unwieldy), and is better served by Improve accessibility of EuiTableRowCell #2335 which we can attack separately).

@snide This mean adding a new prop to EuiBasicTable, correct?

@andreadelrio
Copy link
Contributor Author

I've added a prop, called tableCaption to allow consumer to pass a custom caption if they don't want to use the default. Also removed the aria/role unneeded attributes.

Where do we think the docs note should go? Perhaps somewhere in here?

image

@myasonik
Copy link
Contributor

It definitely doesn't hurt to mention it in there but I was going to say that I think the most important spot is the props documentation which you've already done 👍

@andreadelrio What do you think about changing the default to be column headers instead of number of rows?

@barlowm you might have a good suggestion here for a default as you're the one that's been auditing all these tables

@andreadelrio
Copy link
Contributor Author

@myasonik I've tried adding the names of columns as the default caption. Here's what I currently have:
image

Note: I initially tried to use column.name instead of column.field but found that to be an issue when the consumer defines the column.name doing something like this:

image

Let me know what you think.

@myasonik
Copy link
Contributor

I see what you mean with something like that getting tricky... This isn't ideal but is maybe ok...

@chandlerprall - I wonder if you can help out here. I'm foggy on the details now but I recall you showing me something hidden in EUI to get rendered text that we used for some a11y feature somewhere, I think... Could we use that here?

@snide
Copy link
Contributor

snide commented Jan 27, 2020

@myasonik I think you're referencing this https://elastic.github.io/eui/#/utilities/inner-text

I think we're getting too complicated here for what is still a fairly poor default. Let's remove the columns, leave it with the ability to set the caption manually and make a new issue to revisit this concept later. That unblocks folks. We can always get more complicated later. End of day the best, suggested option is to always write it manually.

@andreadelrio
Copy link
Contributor Author

@myasonik I agree with Dave that this is getting too complicated. I've gone back to having the number of rows as the default caption. I changed it a little bit to remove the use of the word "below" (as you suggested).

Copy link
Contributor

@snide snide left a comment

Choose a reason for hiding this comment

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

Small docs issue. LGTM.

@@ -95,6 +95,12 @@ export const propsInfo = {
required: false,
type: { name: '(criteria: #Criteria) => void' },
},
tableCaption: {
description:
'Describes the content of the table. If not specified, the caption will be "Below is a table of {itemCount} items."',
Copy link
Contributor

Choose a reason for hiding this comment

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

Gonna want to adjust your docs copy to match your recent changes.

Comment on lines 542 to 548
<EuiI18n
token="euiBasicTable.tableDescription"
default="{tableCaption}"
values={{
tableCaption: tableCaption,
}}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary? Usually the consuming app handles translation if it wants it and passes in a translated string.

Comment on lines 545 to 562
<EuiI18n
token="euiBasicTable.tableDescription"
default="This table contains {itemCount} rows out of {totalItemCount} rows."
values={{
totalItemCount: pagination.totalItemCount,
itemCount: items.length,
}}
/>
);
} else {
captionElement = (
<EuiI18n
token="euiBasicTable.tableDescription"
default="This table contains {itemCount} rows."
values={{
itemCount: items.length,
}}
/>
Copy link
Contributor

@thompsongl thompsongl Jan 29, 2020

Choose a reason for hiding this comment

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

These 2 EuiI8ns can't have the same token value because they have different default strings.
Just need to change one or both of their token to something else, like euiBasicTable.tableDescriptionWithPagination/euiBasicTable.tableDescriptionWithoutPagination

@andreadelrio andreadelrio merged commit 31249e5 into elastic:master Jan 29, 2020
@kobelb
Copy link
Contributor

kobelb commented Jan 29, 2020

Thanks for adding this @andreadelrio 🍾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve BasicTable <caption> text
5 participants