-
Notifications
You must be signed in to change notification settings - Fork 578
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov Report
@@ 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
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
What the different between |
@afc163 I was not aware there was a The HTML that is generated by the The |
@afc163 How would you like to proceed with this PR? |
@mellis481 We should deprecated Or we keep |
footer?: PanelRender<RecordType>; | ||
summary?: (data: readonly RecordType[]) => React.ReactNode; | ||
caption?: string | React.ReactNode; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
caption != null ? <caption className={`${prefixCls}-caption`}>{caption}</caption> : undefined; | |
caption !== null && caption !== undefined ? <caption className={`${prefixCls}-caption`}>{caption}</caption> : undefined; |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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.