-
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
fix(Dropdown): use item
instead of as={Menu.Item}
#659
Conversation
Current coverage is 95.84% (diff: 100%)@@ master #659 diff @@
==========================================
Files 879 879
Lines 4889 4889
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 4688 4686 -2
- Misses 201 203 +2
Partials 0 0
|
Though this stops the error, we still have the bug where clicking an item closes the menu, but then switching tabs and switching back opens the dropdown again. This is because it still has focus. This PR should be updated to actually blur the composite component use case. |
@levithomason |
@eXtreme would you care to provide a full example? I tried several variants of using menu.item with dropdown but no luck |
<Menu>
<Menu.Item>
Foo
</Menu.Item>
<Menu.Item as={Dropdown} text="Imma dropdown">
<Dropdown.Menu>
<Dropdown.Item>Foo</Dropdown.Item>
<Dropdown.Item>Bar</Dropdown.Item>
<Dropdown.Divider />
<Dropdown.Item>Baz</Dropdown.Item>
</Dropdown.Menu>
</Menu.Item>
</Menu> Also works with custom |
How about impementing a |
We'll mostly likely do away with using augmentation for this use case. The Dropdown can play the role of a MenuItem or Button, but augmentation is not the right tool for the job. See here: #642. |
Note #659 (comment), this PR is invalid as it circumvents the error by simply removing the feature. It not longer blurs when augmenting a functional component. It needs to be updated to blur in all cases. |
I am trying to guess what the code should do here... _this._dropdown.onBlur(); with _this._dropdown.props.onBlur() It isn't what you expect right? |
No, So, there are 3 possible returns values from the ref The real hang up here on this is the |
bump any big reason why this can't be merged? I have a production app which is suffering |
@Maxhodges have you tried my "workaround" from this comment? |
ah yes, that worked for me. just nicer if I didn't have to workaround ;) |
@Maxhodges refer to the comments I've made above for why this isn't yet merged. |
There is a larger issue here that needs solved. We need a consistent and portable way to deal with refs on stateless functional components. The same solution for this issue will solve #1012. |
@eXtreme tried your workaround..but Menu.Item doesn't take a text attribute anymore, it seems. Any work around so that I can see a bit of text associated with the dropdown? |
@raptoria How is that not working for you? I've tried changing an example on http://react.semantic-ui.com/collections/menu and it works fine with text property. From what I understand, it's RSui's augmentation, which makes the "text" property being actually passed to Dropdown component, as you may see from inspecting with react devtools: "t" is actually the "Dropdown" component, which takes "text" property. The resulting DOM is almost the same as in original SUI (in RSui it has Can you provide an example of this workaround not working? |
@eXtreme I should clarify. Your workaround works, it just gives me a TypeScript error. I'm a TypeScript n00b so I'm not really sure how to fix it. I guess the problem has to do with the text attribute not being explicitly defined in MenuItem. ERROR in ./src/components/FileMenu/FileMenu.tsx this is the code my React component is returning:
any ideas on how to get rid of the error? Thanks!! |
@raptoria, and others who come here looking for a solution, it is most likely that using augmentation (the <Menu attached='top'>
<Dropdown className='item' icon='wrench' />
</Menu> This prevents |
@levithomason thanks! it works perfectly now. |
946a29c
to
2cab8ba
Compare
as={Menu.Item}
usage with item
prop
as={Menu.Item}
usage with item
propitem
instead of as={Menu.Item}
Released in |
* Semantic-Org/master: (111 commits) fix(docs): fix usage of arrow function (Semantic-Org#1228) fix(Icon): Incorrect definition in typings (Semantic-Org#1225) fix(Button): fix `tabIndex` in typings (Semantic-Org#1224) fix(typings): add item prop to the DropdownProps (Semantic-Org#1223) docs(examples): add missing `key` props (Semantic-Org#1220) docs(changelog): update changelog [ci skip] 0.64.4 feat(Form): add `inverted` prop (Semantic-Org#1218) fix(ComponentExample): use explicit babel presets (Semantic-Org#1219) style(Button): update typings and propTypes usage (Semantic-Org#1216) style(Embed): update typings and propTypes usage (Semantic-Org#1217) chore(package): support for jsnext:main (Semantic-Org#1210) style(Step): update typings, tests and propTypes usage (Semantic-Org#1203) fix(Portal): do not take focus after first render (Semantic-Org#1215) style(Table|mixed): update typings, tests and propTypes usage (Semantic-Org#1200) fix(Dropdown): use `item` instead of `as={Menu.Item}` (Semantic-Org#659) fix(Dropdown): respect `closeOnBlur={false}` (Semantic-Org#1148) style(Breadcrumb): update typings and propTypes usage (Semantic-Org#1209) style(Dimmer): update typings (Semantic-Org#1208) fix(Divider|FormInput): fix the broken typings (Semantic-Org#1179) ...
fix(Dropdown): use `item` instead of `as={Menu.Item}`
Update
Augmenting the Dropdown with a
Menu.Item
is no longer supported. Instead, use theitem
prop when using a Dropdown as a menu item. See the changes in this PR for more:Before
After
Original Post
Per #628 (comment), this PR checks for
this._dropdown.blur()
before calling it. When augmented, theref
may be a composite component ref instead of an actual DOM node. Otherwise, we sometimes get:Uncaught TypeError: a._dropdown.blur is not a function
.