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(Dropdown): handle text as a content in renderLabel #4047

Merged
merged 1 commit into from
Sep 8, 2020

Conversation

layershifter
Copy link
Member

Fixes #4046.


This PR fixes a regression from #4003 (v1.1.0).

That change affected renderLabel prop in Dropdown (will be used to render labels with multiple). In #4003 I decided to avoid breaking changes and keep the existing behavior via this condition:

if (React.isValidElement(text) || _.isFunction(text)) {

However, I can't consider the previous behavior as valid as it will break the layout once text will be a JSX element (see behaviors below).

test snippet

<Grid columns={2}>
  <Grid.Column>
    <Dropdown
      placeholder="Select Friend"
      fluid
      selection
      multiple
      options={[
        {
          key: "Jenny Hess",
          text: <span>Jenny Hess</span>,
          value: "Jenny Hess"
        },
        {
          key: "Elliot Fu",
          text: "Elliot Fu",
          value: "Elliot Fu"
        }
      ]}
    />
  </Grid.Column>
  <Grid.Column>
    <Dropdown
      placeholder="Select Friend"
      fluid
      selection
      options={[
        {
          key: "Jenny Hess",
          text: <span>Jenny Hess</span>,
          value: "Jenny Hess"
        },
        {
          key: "Elliot Fu",
          text: "Elliot Fu",
          value: "Elliot Fu"
        }
      ]}
    />
  </Grid.Column>
</Grid>

Mention that in the first case text is a JSX element.

pre v1.1.0 behavior

image

https://codesandbox.io/s/busy-hooks-5p5pq

v1.1.0 behavior

image
https://codesandbox.io/s/distracted-dawn-xg28c

fix in this PR

image


To keep previous behavior use:

<Dropdown renderLabel={({ text }) => text} />

@github-actions
Copy link

size-limit report

Path Size
bundle-size/dist/Button.size.js 66.39 KB (0%)
bundle-size/dist/Icon.size.js 30.58 KB (0%)
bundle-size/dist/Image.size.js 61.63 KB (0%)
bundle-size/dist/Modal.size.js 76.65 KB (0%)
bundle-size/dist/Portal.size.js 47.78 KB (0%)

@codecov-commenter
Copy link

codecov-commenter commented Aug 26, 2020

Codecov Report

Merging #4047 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4047   +/-   ##
=======================================
  Coverage   99.84%   99.84%           
=======================================
  Files         186      183    -3     
  Lines        3255     3280   +25     
=======================================
+ Hits         3250     3275   +25     
  Misses          5        5           
Impacted Files Coverage Δ
src/addons/Portal/Portal.js 100.00% <ø> (ø)
src/addons/Portal/PortalInner.js 100.00% <ø> (ø)
src/addons/TextArea/TextArea.js 100.00% <ø> (ø)
src/behaviors/Visibility/Visibility.js 100.00% <ø> (ø)
src/collections/Form/FormField.js 100.00% <ø> (ø)
src/elements/Button/Button.js 95.55% <ø> (ø)
src/elements/Input/Input.js 100.00% <ø> (ø)
src/elements/Placeholder/Placeholder.js 100.00% <ø> (ø)
src/modules/Checkbox/Checkbox.js 100.00% <ø> (ø)
src/modules/Dimmer/DimmerInner.js 100.00% <ø> (ø)
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c3640e4...c4c62b0. Read the comment docs.

@layershifter layershifter merged commit 859146f into master Sep 8, 2020
@layershifter layershifter deleted the fix/dropdown-text branch September 8, 2020 14:27
@layershifter
Copy link
Member Author

Released in [email protected] 🚢

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

Successfully merging this pull request may close these issues.

Dropdown text no longer has a <div class="text"> wrapper if text is an element
2 participants