Skip to content

Added conditional rendering to description in EuiCard#4582

Merged
cchaos merged 13 commits intoelastic:masterfrom
hetanthakkar:EuiCard
Mar 16, 2021
Merged

Added conditional rendering to description in EuiCard#4582
cchaos merged 13 commits intoelastic:masterfrom
hetanthakkar:EuiCard

Conversation

@hetanthakkar
Copy link
Copy Markdown
Contributor

@hetanthakkar hetanthakkar commented Feb 25, 2021

This conditional rendering will prevent redundant render caused when description in EuiCard is false

Checklist

  • Check against all themes for compatibility in both light and dark modes
  • Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • Props have proper autodocs and playground toggles
  • Added documentation
  • Checked Code Sandbox works for the any docs 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

@kibanamachine
Copy link
Copy Markdown

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

</EuiText>
{description && (
<EuiText
id={`${ariaId}Description`}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wherever in the file we reference this ID, now has to be conditional as well.

(An aria-describedby={id} that doesn't find that id will cause automated accessibility tests to often fail.)

@hetanthakkar
Copy link
Copy Markdown
Contributor Author

@myasonik I have made changes. but I'm a bit skeptical about my approach. Could you please review my changes

Copy link
Copy Markdown
Contributor

@myasonik myasonik left a comment

Choose a reason for hiding this comment

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

@hetanthakkar1 Your approach did technically work at not rendering invalid aria-describedby attributes but it's a little heavy handed in what else it doesn't render 😄

If we move the conditional a little closer to the problem area, we can still render everything else we need to.

if (selectable && description) {
optionalSelectButton = (
<EuiCardSelect
aria-describedby={`${ariaId}Title ${ariaId}Description`}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If earlier in the file you define a variable something like:

const ariaDesc = description ? `${ariaId}Description` : '';

Then you can use it in place of everywhere it's used now

Suggested change
aria-describedby={`${ariaId}Title ${ariaId}Description`}
aria-describedby={`${ariaId}Title ${ariaDesc}`}

Copy link
Copy Markdown
Contributor Author

@hetanthakkar hetanthakkar Feb 27, 2021

Choose a reason for hiding this comment

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

I thought of doing the same const ariaDesc = description ? ${ariaId}Description : ''; .But I wasn't sure what should value ariaDesc take i.e. whether ariaDesc = ' ' would work!


let optionalSelectButton;
if (selectable) {
if (selectable && description) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We still want to render this content if the description is empty so we can't just not render the whole thing

@hetanthakkar
Copy link
Copy Markdown
Contributor Author

@myasonik I have incorporated the changes. Could you please review

@myasonik
Copy link
Copy Markdown
Contributor

Jenkins test this

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4582/

@hetanthakkar
Copy link
Copy Markdown
Contributor Author

@myasonik I am just curious to know why eui-ci build fails so frequently! Most probably it's not related to my PR but is there a way we can fix it

@hetanthakkar
Copy link
Copy Markdown
Contributor Author

@myasonik Is there anything else i need to change in the code!?

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Mar 1, 2021

I am just curious to know why eui-ci build fails so frequently!

We've been having a lot of timeouts recently due to the increase in build time. If you update from master you should get a most recent PR that should help reduce the timeouts.

@myasonik
Copy link
Copy Markdown
Contributor

myasonik commented Mar 1, 2021

@hetanthakkar1 I merged master for you so that we can check CI. Code changes look OK though if no tests fail for this and need updating, we probably should add some.

@myasonik
Copy link
Copy Markdown
Contributor

myasonik commented Mar 1, 2021

jenkins test this

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4582/

@hetanthakkar
Copy link
Copy Markdown
Contributor Author

@cchaos

We've been having a lot of timeouts recently due to the increase in build time. If you update from master you should get a most recent PR that should help reduce the timeouts.

Okay got it! Thanks

@hetanthakkar
Copy link
Copy Markdown
Contributor Author

@hetanthakkar1 I merged master for you so that we can check CI. Code changes look OK though if no tests fail for this and need updating, we probably should add some.

Ohkayy. Thanks @myasonik !

Copy link
Copy Markdown
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Thanks for getting this one started @hetanthakkar1 . There's still some more tasks to complete before we can merge this PR. We usually track these by the checklist that comes pre-filled in the PR summaries, so be sure not to delete that when creating PR's. I've added it back in to your PR summary and crossed off the unapplicable ones.

Since we're now conditionally rendering description we also need to mark the prop as optional. And since this is a pretty major change to the component, we should update at least one of the examples under the Custom children section. Probably just remove the description from the middle (form) one.

Screen Shot 2021-03-01 at 10 34 14 AM

Also, as @myasonik suggested, we'll need a test for this as well. You can find the associated testing file ending in test.ts

CHANGELOG.md Outdated
- Removed static `id` from `EuiQuickSelectPopover` ([#4543](https://github.com/elastic/eui/pull/4543))
- Fixed support sever side rendering for `EuiDataGrid` ([#4540](https://github.com/elastic/eui/pull/4540))

- Fixed redundant render caused in `EuiCard` when `description` is false ([#4546]https://github.com/elastic/eui/pull/4582)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Fixed redundant render caused in `EuiCard` when `description` is false ([#4546]https://github.com/elastic/eui/pull/4582)
- Made `description` prop of `EuiCard` optional ([#4546]https://github.com/elastic/eui/pull/4582)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This CL entry also now has to move up to the top section under master

@chandlerprall
Copy link
Copy Markdown
Contributor

chandlerprall commented Mar 2, 2021

Since we're now conditionally rendering description we also need to mark the prop as optional.

Do we want to? I kinda like keeping it required with allowing a false or empty string '' value (as it is today), both of which wouldn't render under an if (description) condition. Feels like it's a mechanism to help ensure an implementation had to intentionally avoid a description.

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Mar 2, 2021

If we go that route, then I think we at least need to be explicit about the boolean case in the prop types and add a prop comment explaining it.

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Mar 2, 2021

We talked about this in our weekly sync. Since the basic idea here is still wanting to require a description by default, but allow consumers to sort of override with their own children, we'll want to setup an ExclusiveUnion that if children is provided then description is optional.

@chandlerprall
Copy link
Copy Markdown
Contributor

@hetanthakkar1 I've pushed a couples commits to make description optional if children is present. @cchaos please check the updated comment for description.

I verified with:

const TestComponent = () => (
  <>
    {/* these are fine */}
    <EuiCard title="A Card" description="A really cool feature." />
    <EuiCard title="A Card" children="A really cool feature." />
    <EuiCard title="A Card">A really cool feature.</EuiCard>
    <EuiCard title="A Card" description="A really cool feature.">
      A really cool feature.
    </EuiCard>

    {/* only this one errors */}
    <EuiCard title="A Card" />
  </>
);

Screen Shot 2021-03-02 at 12 17 07 PM

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Mar 2, 2021

👍 Yup makes sense to me!

I'd still also like to see an update to that middle example under Custom children to remove the description prop.

@hetanthakkar

This comment has been minimized.

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Mar 8, 2021

@hetanthakkar1 I've commented on your other PR. We try to keep questions/conversations in their respective PR's and issues just to make it easy to follow in the future.

@hetanthakkar
Copy link
Copy Markdown
Contributor Author

@cchaos I have removed that middle example. Could you please review it

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Mar 11, 2021

Jenkins, test this

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4582/

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Mar 11, 2021

Jenkins, test this

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4582/

@cchaos cchaos requested a review from myasonik March 11, 2021 16:05
Copy link
Copy Markdown
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

@hetanthakkar1 I've updated this PR to fix more of the checklist items. 👍 From design.

@chandlerprall can you do a pass on the TS?

@cchaos cchaos requested a review from chandlerprall March 11, 2021 16:06
Copy link
Copy Markdown
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Everything looks good, have one small recommendation.

@hetanthakkar
Copy link
Copy Markdown
Contributor Author

I have made the necessary changes. Could you please review it

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Mar 11, 2021

Jenkins, test this

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4582/

@hetanthakkar
Copy link
Copy Markdown
Contributor Author

@cchaos could you merge it

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Mar 15, 2021

could you merge it

Just waiting on @chandlerprall's final review from the change he requested.

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Mar 16, 2021

I re-checked through the changes including the aria stuff. Looks good to me. I'll rerun Jenkins one more time then merge
Jenkins, test this.

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_4582/

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.

5 participants