-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Dropdown: Support arbitrary element for text
#477
Comments
I believe the goal is the ability to use any Dropdown trigger element. If so, I'm in full support as it's something that has been on my thought list as well. I think it would be great to be able to have any "trigger" component open any "menu" component. I'm not sure where the optimal place to do this is. It may be the
All said, I don't have any great proposal ATM either. ...20m later, I experimented with adding a Dropdown.js renderText = () => {
+ if (this.props.trigger) return this.props.trigger
const { multiple, placeholder, search, text } = this.props
const { searchQuery, value, open } = this.state Example import React from 'react'
import { Image, Dropdown } from 'stardust'
const trigger = <Image avatar src='https://avatars2.githubusercontent.com/u/5067638?v=3&s=40' />
const DropdownUserMenuExample = () => (
<Dropdown pointing='top right' trigger={trigger} icon='caret down'>
<Dropdown.Menu>
<Dropdown.Item disabled>
<div>Signed In as levithomason</div>
<strong>levithomason</strong>
</Dropdown.Item>
<Dropdown.Divider />
<Dropdown.Item>Your Profile</Dropdown.Item>
<Dropdown.Item>Your Stars</Dropdown.Item>
<Dropdown.Item>Explore</Dropdown.Item>
<Dropdown.Item>Integrations</Dropdown.Item>
<Dropdown.Item>Help</Dropdown.Item>
<Dropdown.Divider />
<Dropdown.Item>Settings</Dropdown.Item>
<Dropdown.Item>Sign Out</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
)
export default DropdownUserMenuExample Result I'm not a fan of creating complicated elements and passing them through props, but it is cleaner than trying to parse out a specific child IMO. Also, this would conflict with any Feedback? |
Testing more examples, I think you're absolutely right about using the text section of the Dropdown markup. I've still mapped it to For the Card example, I've passed a <Card.Content extra>
<Dropdown trigger={<a><Icon name='user' /> 16 Friends</a>}>
... For kicks, I also passed an entire Card component as the trigger, which as you'd expect, works just fine. |
I'd accept a PR for this. |
Awesome! It seems like there are two main (but pretty different) uses for the
There's a ton of support for the first case, not much for the second. I think having something like a customizable trigger would go along way in making the second case more developer-friendly. I think those examples you whipped up help make the case. |
Agreed, this is why we created the |
I am facing this issue:
Here is the code:
The state variables are set in the custom methods(It's too lengthy to add here). Any idea what's wrong? Thanks in advance. |
@akhilaudable For usage questions use Stack Overflow. Please refrain from commenting very old resolved bugs looking for help. |
My use-case
I have a menu that I want to be triggered by a custom element. It's not a
select
-type dropdown, just a menu of items that becomes visible after clicking this element.EDIT: To give a more concrete example, think of something like the github user menu with a custom
<Avatar />
component:Currently, you can specify text for the dropdown:
Ideally I'd want to be able to pass in a custom component that gets rendered where the
text
currently does. For example:Note: This is different than using
as={MyCustomComponent}
, which would render the outer container asMyCustomComponent
:I only want to render the
text
portion to be custom.I could also see allowing composing the dropdown text manually via
Dropdown.Text
like:Thoughts?
The text was updated successfully, but these errors were encountered: