-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
breaking(Dropdown): add options shorthand #1038
Conversation
src/modules/Dropdown/Dropdown.js
Outdated
PropTypes.arrayOf(PropTypes.shape(DropdownItem.propTypes)), | ||
]), | ||
/** Array of Dropdown.Item shorthand */ | ||
options: customPropTypes.itemShorthand, |
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.
I think this should be collectionShorthand
This is going to affect methods like: getItemByValue = (value) => {
const { options } = this.props
return _.find(options, { value })
} I kinda think we're gonna need to:
Passing it through the factory first would allow us to predictably access a prop (text, value, whatever) of an item. Also if we do it this way, maybe update |
Thanks for the extra eyes. Indeed, I'll be sure to make these changes prior to merging. This PR is half baked atm. |
I'm not sure this is the place, but react-widgets has a nice ish API allowing options to be an array of objects and two optional props. One to specify the display value and another for the value to be selected.
|
@UnbrandedTech use |
321c2e2
to
50d470e
Compare
Codecov Report
@@ Coverage Diff @@
## master #1038 +/- ##
==========================================
- Coverage 99.74% 99.66% -0.08%
==========================================
Files 140 140
Lines 2345 2396 +51
==========================================
+ Hits 2339 2388 +49
- Misses 6 8 +2
Continue to review full report at Codecov.
|
0fb5701
to
3c6a438
Compare
431d47c
to
61a8073
Compare
faa39c3
to
b4040bc
Compare
Closing this PR as it has gotten too stale. Also, I'm not sure this work is worth it. The gains are minor and the repercussions are major. |
TODO
Breaking Changes!
This PR updates the Dropdown to allowing defining options with any shorthand value: number, string, props object, or another element.
options
prop renamed toitems
As a design decision, shorthand props are provided for each subcomponent. Example, a
Modal
with<Modal.Header>Foo</Modal.Header>
can be configured as<Modal header='Foo' />. The Dropdown
optionsprop is used to create
<Dropdown.Item />s, hence, the correct shorthand prop name is
items`.Before
After
New
search
callback signatureThe
items
are used to create<DropdownItem />
s internally. Customsearch
functions, which used to receive the originalitems
objects, now receive<DropdownItem />
instances. Use the instance'sprops
to access thetext
,value
, and otherprops
as necessary.Before
After
New
renderLabel
callback signatureMultiple select Dropdowns can render a custom
Label
for each activeDropdownItem
. This callback, which used to receive a singleoption
object, now receives a<DropdownItem />
instance. Use the instance'sprops
to access thetext
,value
, and otherprops
as necessary.Before
After
Fixes #470
This adds shorthand factory support to the Dropdown
options
.