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

Fix rendering choice-list child components #319

Merged
merged 2 commits into from
May 23, 2019

Conversation

vladucu
Copy link
Member

@vladucu vladucu commented May 23, 2019

What's here

This is a follow up on #318
Found out that with #318, we'll always render the wrapping Polaris-ChoiceList__ChoiceChildren div when there's a childComponent for a choice, which cause some extra spacing.

This:

  • changes so that by default we render the childComponent only when the choice is selected
  • adds an extra alwaysRenderChildComponent property, which when true will always render the childComponent

@vladucu vladucu requested a review from andrewpye May 23, 2019 13:42
@vladucu vladucu self-assigned this May 23, 2019
{{#if
(and
choice.childComponent
(or choice.isSelected choice.alwaysRenderChildComponent)
Copy link
Member

Choose a reason for hiding this comment

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

In the React implementation, the logic of whether the children should be rendered is completely independent of whether the choice is selected - that decision is left to the outside world. How do you feel about replacing this line with choice.shouldRenderChildComponent and let the outside world decide on this logic, the same way users of the React version can?

Copy link
Member Author

Choose a reason for hiding this comment

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

I see what you mean...but how would that look in real world usage....can you add an example?

The React implementation just invokes a function and passes isSelected so the outside world can decide and return actual DOM....we could try to mimic this (just the deciding part) with an action for the choice, something like renderChildComponent....but although this matches a bit more what React implementation does....it's not really usage-friendly

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking usage would look something like this, if we wanted to only render the child component when the item was selected:

<PolarisChoiceList
  ...
 @choices={{array
    (hash
      label="Option 1"
      value="one"
    )
    (hash
      label="Option 2"
      value="two"
      childComponent=(component "polaris-text-field" ...)
      shouldRenderChildComponent=(eq this.selected "two")
    )
  }}
  @selected={{this.selected}}
  ...
/>

This would, however, need the outside world to track whether each option was selected, which would likely be a bit clunky now I've looked into it.

Instead, how would you feel about a potential solution that's slightly hacky on the inside, but makes these problems go away for the outside world? 😅 What if we used the choice list's didRender/willRender hooks to auto-wrap/unwrap the children components based on whether anything's rendered or not? Means the outside world doesn't have to specify whether they want the child component to be rendered or not... 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Instead, how would you feel about a potential solution that's slightly hacky on the inside, but makes these problems go away for the outside world? 😅 What if we used the choice list's didRender/willRender hooks to auto-wrap/unwrap the children components based on whether anything's rendered or not? Means the outside world doesn't have to specify whether they want the child component to be rendered or not...

As you know from our current experience with auto-wrapping, that's pretty error-prone

As it's clear we can't match exactly the React implementation, I think we should aim for the simplest API - not saying what's in here now is it, but personally find it nicer than other suggestions.....open to others too...nothing else comes to my mind right now though

Copy link
Member

Choose a reason for hiding this comment

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

As you know from our current experience with auto-wrapping, that's pretty error-prone

Yes, although the thought above made me realise that we could look into using willRender to clean up auto-wrapped children. I've tried a quick experiment with it, but haven't been able to reproduce the issue we've seen before in testing 🤦‍♂

With that in mind, maybe we should go with what's here for now despite it being less than ideal, and update later if we're able to 🤷‍♂

Copy link
Member Author

Choose a reason for hiding this comment

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

will add a TODO here and maybe we find something nicer soon

@andrewpye
Copy link
Member

Looks like we've got some build issues on CI 😭

@vladucu
Copy link
Member Author

vladucu commented May 23, 2019

Looks like we've got some build issues on CI

Seems like npm issues...Heroku builds are also failing

@vladucu vladucu merged commit 3167383 into master May 23, 2019
@delete-merged-branch delete-merged-branch bot deleted the fix/choice-list-children-rendering branch May 23, 2019 16:32
@sivakumar-kailasam sivakumar-kailasam added the bug Something isn't working label Jun 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants