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

Adds ability to define a caption #856

Merged
merged 3 commits into from
Aug 24, 2022

Conversation

mellis481
Copy link
Contributor

Captions provide information that can help users find, navigate, and understand tables. While they are not required in every case to meet WCAG, captions are fairly straightforward ways to provide such information that is often needed.

This PR adds an optional caption prop to the Table component to allow users to define a caption using a string or a ReactNode.

@vercel
Copy link

vercel bot commented Jul 27, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
table ✅ Ready (Inspect) Visit Preview Aug 17, 2022 at 0:40AM (UTC)

@codecov
Copy link

codecov bot commented Jul 28, 2022

Codecov Report

Merging #856 (912d1d0) into master (1a485d8) will increase coverage by 0.00%.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #856   +/-   ##
=======================================
  Coverage   99.39%   99.39%           
=======================================
  Files          36       36           
  Lines         987      988    +1     
  Branches      282      297   +15     
=======================================
+ Hits          981      982    +1     
  Misses          6        6           
Impacted Files Coverage Δ
src/Table.tsx 99.19% <ø> (+<0.01%) ⬆️
src/utils/legacyUtil.ts 100.00% <ø> (ø)
src/hooks/useColumns.tsx 100.00% <0.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@afc163
Copy link
Member

afc163 commented Jul 28, 2022

What the different between title and caption, could caption replace title completely?

@mellis481
Copy link
Contributor Author

mellis481 commented Jul 29, 2022

@afc163 I was not aware there was a title prop in rc-table, but after reviewing it yes, caption should replace title completely.

The HTML that is generated by the title prop is purely visual and the rendered elements are not associated with the table at all. A screen reader will not announce the title when it reads information about the table.

The caption element, however, in addition to appearing visually, is programmatically associated with the table and, therefore, announced by screen readers when it reads information about the table.

@mellis481
Copy link
Contributor Author

@afc163 How would you like to proceed with this PR?

@Ke1sy
Copy link

Ke1sy commented Aug 9, 2022

@afc163 This PR along with #855 and #859 provide important accessibility fixes that my team needs for our users. Can you please work to get them in soon?

@afc163
Copy link
Member

afc163 commented Aug 9, 2022

@mellis481 We should deprecated title and recommend caption instead.

Or we keep title prop without adding caption but replace dom node by <caption /> in current implementation.

footer?: PanelRender<RecordType>;
summary?: (data: readonly RecordType[]) => React.ReactNode;
caption?: string | React.ReactNode;
Copy link
Member

Choose a reason for hiding this comment

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

Or we keep title prop without adding caption but replace dom node by in current implementation.

Is it a better proposal?

Copy link
Contributor Author

@mellis481 mellis481 Aug 9, 2022

Choose a reason for hiding this comment

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

@afc163 If we want to avoid a breaking change, refactoring how the existing title prop gets used (inside a <caption>) would be the better option. If we want to potentially avoid confusing consumers who are expecting a caption prop rather than a title prop, the first option would be better. I just pushed a commit deprecating title because I tend to favor what I consider is ultimately the best long-term solution, but let me know if you want to go with the other option.

src/Table.tsx Outdated
@@ -609,6 +610,9 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
<ColGroup colWidths={flattenColumns.map(({ width }) => width)} columns={flattenColumns} />
);

const captionElement =
caption != null ? <caption className={`${prefixCls}-caption`}>{caption}</caption> : undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
caption != null ? <caption className={`${prefixCls}-caption`}>{caption}</caption> : undefined;
caption !== null && caption !== undefined ? <caption className={`${prefixCls}-caption`}>{caption}</caption> : undefined;

Copy link
Contributor Author

@mellis481 mellis481 Aug 10, 2022

Choose a reason for hiding this comment

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

!= null accounts for null and undefined. I'm unclear the purpose of explicitly checking for null and undefined.

I'm actually thinking !! may be more appropriate so we don't render a <caption> if the prop is another falsy value (eg. 0, '', false) (since React.ReactNode can be almost anything).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@afc163 Let's get this PR merged. Are you OK if I use !! for the reason above?

Copy link
Member

Choose a reason for hiding this comment

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

!= should not be used in any circumstance

Copy link
Contributor Author

@mellis481 mellis481 Aug 17, 2022

Choose a reason for hiding this comment

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

!= should not be used in any circumstance

That's an interesting assertion. Could you share information or an article explaining why you believe that?

In any event, I've made the change you requested and I believe this was the only outstanding comment.

@mellis481
Copy link
Contributor Author

@zombieJ @afc163 Let's get this merged please.

@afc163 afc163 merged commit c6af77e into react-component:master Aug 24, 2022
@mellis481 mellis481 deleted the adds-caption branch October 20, 2022 17:28
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.

None yet

3 participants