question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFC: Dropdown header and divider shorthands

See original GitHub issue

https://react.semantic-ui.com/modules/dropdown#dropdown-example-header

I wanna use Dropdown.Header and Dropdown.Divider in search or multiple dropdown, but it’s currently not supported. So I suppose we should extend shorthand props to support it. But it can be done in many ways so it’s better to consider different options.

Header

I think the header shorthand is pretty straitforward

import React from 'react'
import { Dropdown } from 'semantic-ui-react'

const options = [
  { content: 'Important', header: { icon: 'tags', content: 'Filter by tag' } },
  { content: 'Announcement' },
  { content: 'Discussion' }
]

// <Dropdown.Header icon='tags' content='Filter by tag' />
// <Dropdown.Item>Important</Dropdown.Item>
// <Dropdown.Item>Announcement</Dropdown.Item>
// <Dropdown.Item>Discussion</Dropdown.Item>

const DropdownExampleHeader = () => (
  <Dropdown text='Filter' icon='filter' floating labeled button className='icon' options={options} />
)

export default DropdownExampleHeader

Divider

I think it should be implemented by using divider shorthand with position as shorthand value. Possible positions will be 'top' | 'bottom' | 'both'.

import React from 'react'
import { Dropdown } from 'semantic-ui-react'

const options = [
  { content: 'Important' },
  { content: 'Announcement', divider: 'top' },
  { content: 'Discussion' }
]

// <Dropdown.Item>Important</Dropdown.Item>
// <Dropdown.Divider />
// <Dropdown.Item>Announcement</Dropdown.Item>
// <Dropdown.Item>Discussion</Dropdown.Item>

const DropdownExampleDivider = () => (
<Dropdown text='Filter' icon='filter' floating labeled button className='icon' options={options} />
)

export default DropdownExampleDivider

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
levithomasoncommented, Jun 1, 2017

Thank you for starting this RFC. In addition to the linked #889, it is also closely related to #1365 (submenu’s and nested dropdown menu’s).

I’d propose that we standardize on the component key to define which component the props are for. This would apply to any shorthand. Updating the example Dropdowns you provided above:

Header

const options = [
  { component: Dropdown.Header, icon: 'tags', content: 'Filter by tag' },
  { content: 'Important' },
  { content: 'Announcement' },
  { content: 'Discussion' }
]

// <Dropdown.Header icon='tags' content='Filter by tag' />
// <Dropdown.Item>Important</Dropdown.Item>
// <Dropdown.Item>Announcement</Dropdown.Item>
// <Dropdown.Item>Discussion</Dropdown.Item>

Divider

const options = [
  { content: 'Important' },
  { component: Dropdown.Divider },
  { content: 'Announcement' },
  { content: 'Discussion' }
]

// <Dropdown.Item>Important</Dropdown.Item>
// <Dropdown.Divider />
// <Dropdown.Item>Announcement</Dropdown.Item>
// <Dropdown.Item>Discussion</Dropdown.Item>
0reactions
DreierFcommented, Sep 5, 2021

What seems to do the trick after #4029 is to define headers and dividers as follows within the dropdown options:

const options = [
  {
    key: "header1",
    children: () => <Dropdown.Header content="Header" />,
    disabled: true
  },
  {
    key: "divider1",
    children: () => <Dropdown.Divider />,
    disabled: true
  },
  {
    key: "key1",
    value: "value1",
    text: "value1"
  },
...
];
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap class: .dropdown-divider
Bootstrap CSS class dropdown-divider with source code and live preview. You can copy our examples and paste them into your project!
Read more >
Dropdown - Semantic UI React
A dropdown menu can contain dividers to separate related content. ... Dropdown state is not fully managed when using the subcomponent API. The...
Read more >
pentacle keyboard symbol
Choose your font from the Font drop-down menu. RIGHT-HANDED INTERLACED PENTAGRAM ⛥, SAILBOAT. They see their organization as eternal and impossible to ...
Read more >
Dropdown | Fomantic-UI Docs
A dropdown allows a user to select a value from a series of options. ... A dropdown menu can contain dividers to separate...
Read more >
Dropdowns - Bootstrap
Wrap the dropdown's toggle (your button or link) and the dropdown menu ... else here</a> <div class="dropdown-divider"></div> <a class="dropdown-item" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found