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

feat(Dropdown): support additionLabel components #757

Merged
merged 1 commit into from
Oct 31, 2016

Conversation

jayphelps
Copy link
Contributor

@jayphelps jayphelps commented Oct 28, 2016

Dropdown now wraps additions in <b> tags and uses additionPosition="top" by default, just like the jQuery semantic-ui plugin.

image

There is also some more subtle changes to align with the jQuery version:

  • default additionLabel is now "Add" without the semicolon, and includes the space between the label and the addition. This allows users to use labels which do not wish to have space between the two.
    • this overall API differs from the jQuery version which uses unsafe templates: addResult : 'Add <b>{term}</b>'. We could instead use callbacks, if even more alignment was preferred. addResult={term => <span>Add <b>{term}</b></span>
    • or of course, we could use templates too and use dangerouslySetInnerHTML 😨
  • The addition item now has the addition className added to it--this can be important for themes

You will notice that, because of a React limitation/design I am passing text as an array of elements. Because of the current way the React diffing algorithm works, even though these elements will always be in the same order we must define a key for them. This isn't pretty--but at least for me, having the same styling behavior of the wrapped <b> is critical to UX.


This was my first experience with enzyme/chai-enzyme so lmk if there is a better way to write the prop tests that contain the array of elements. It's not ideal 😞

@codecov-io
Copy link

codecov-io commented Oct 28, 2016

Current coverage is 99.48% (diff: 100%)

Merging #757 into master will decrease coverage by <.01%

@@             master       #757   diff @@
==========================================
  Files           136        134     -2   
  Lines          2183       2154    -29   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits           2172       2143    -29   
  Misses           11         11          
  Partials          0          0          

Powered by Codecov. Last update 0b93783...88911a5

@levithomason
Copy link
Member

This is awesome, thanks! Would you consider adding an example showing use of a custom additionLabel?

@jayphelps
Copy link
Contributor Author

@levithomason to docs/app/Examples/modules/Dropdown/Usage ?

something like this?

render() {
  // etc

  <Dropdown
    additionLabel="Custom: "
    {...etc}
  />

  // etc

  <Dropdown
    additionLabel={<i>Custom: </i>}
    {...etc}
  />
}

@levithomason
Copy link
Member

levithomason commented Oct 28, 2016

Exactly. Two separate example files would be superb. One showing a text label, and a separate one showing a component example.

@jayphelps
Copy link
Contributor Author

Added requested examples. 🎉

@jayphelps
Copy link
Contributor Author

jayphelps commented Oct 31, 2016

Note: I forgot to mention that this is technically a breaking change and I have added such in the commit message for commitizen

BREAKING CHANGE: Dropdown now now wraps additions in and uses
additionPosition="top" by default

@levithomason
Copy link
Member

levithomason commented Oct 31, 2016

This looks great! Just one lint issue to fix that is failing CI:

image

…Position="top", just like the jQuery semantic-ui plugin

BREAKING CHANGE: Dropdown now now wraps additions in \<b> and uses
additionPosition="top" by default.
@jayphelps
Copy link
Contributor Author

doh! fixed. I incorrectly assumed it would lint as part of the test runner. Might be helpful to create a pre-commit hook that lints the code.

@levithomason
Copy link
Member

levithomason commented Oct 31, 2016

We used a few pre-commit hooks solutions but found them to be problematic. We just rely on the PR status. Though, this obviously needs be a little more clear to developers! Thanks for the feedback.

@levithomason
Copy link
Member

Could you clarify something regarding the breaking change? I'd like to release this as a feature rather than an API change. My understanding:

  • The exposed API hasn't change
  • The previous additionLabel accepted plain text only
  • The default additionPosition changed
  • The additionLabel is now bold

My conclusion based on ^ these points is that old additionLabel code will still work, it will just be bold and default to the top of the Dropdown. I see this as a non-breaking feature. What are your thoughts?

@levithomason
Copy link
Member

I'm actually going to release this as a feature and we can adjust if there are issues 👍

@levithomason levithomason changed the title Better Dropdown alignment with jQuery plugin behavior feat(Dropdown): support additionLabel components Oct 31, 2016
@levithomason levithomason merged commit 2b594d0 into Semantic-Org:master Oct 31, 2016
@jayphelps
Copy link
Contributor Author

@levithomason okiedokie :shipit:

@levithomason
Copy link
Member

Released in semantic-ui-react@0.58.1

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.

3 participants