Skip to content

Commit

Permalink
The alignment of dropdown menu wrapper should take effect when the pu…
Browse files Browse the repository at this point in the history
…llRight prop is specified
  • Loading branch information
cheton committed May 2, 2018
1 parent a264f4d commit ef6c623
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,12 @@ btnStyle | One of:<br/>'default'<br/>'primary'<br/>'emphasis'<br/>'flat'<br/>'li
noCaret | boolean | false | Whether to prevent a caret from being rendered next to the title.
title | node | | Title content.
disabled | boolean | false | Whether or not component is disabled.
open | boolean | false | Whether or not the dropdown is visible.

#### DropdownMenu

Name | Type | Default | Description
:--- | :--- | :------ | :----------
componentClass | element | ul | A custom element for this component.
open | boolean | false | Whether or not the dropdown is visible.
pullRight | boolean | false | Align the menu to the right side of the dropdown toggle.
onClose | function(event) | | A callback fired when the dropdown menu closes.
onSelect | function(eventKey, event) | | A callback fired when a menu item is selected.
rootCloseEvent | One of:<br/>'click'<br/>'mousedown' | | Which event when fired outside the component will cause it to be closed.
Expand All @@ -266,8 +263,6 @@ rootCloseEvent | One of:<br/>'click'<br/>'mousedown' | | Which event when fired
Name | Type | Default | Description
:--- | :--- | :------ | :----------
componentClass | element | div | A custom element for this component.
open | boolean | false | Whether or not the dropdown is visible.
pullRight | boolean | false | Align the menu to the right side of the dropdown toggle.
onClose | function(event) | | A callback fired when the dropdown menu closes.
onSelect | function(eventKey, event) | | A callback fired when a menu item is selected.
rootCloseEvent | One of:<br/>'click'<br/>'mousedown' | | Which event when fired outside the component will cause it to be closed.
Expand All @@ -284,7 +279,6 @@ eventKey | any | | Value passed to the `onSelect` handler, useful for identifyin
header | boolean | false | Style the menu item as a header label, useful for describing a group of menu items.
onClick | function(event) | | Callback fired when the menu item is clicked, even if it is disabled.
open | boolean | false | Whether or not the dropdown submenu is visible.
pullRight | boolean | false | Align the menu to the right side of the dropdown toggle.
onClose | function(event) | | A callback fired when the dropdown menu closes.
onSelect | function(eventKey, event) | | A callback fired when a menu item is selected.
rootCloseEvent | One of:<br/>'click'<br/>'mousedown' | | Which event when fired outside the component will cause it to be closed.
Expand Down
6 changes: 4 additions & 2 deletions examples/DropdownMenuWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ export default () => (
<div className={styles.sectionGroup}>
<h3>Dropdown Menu Wrapper</h3>
<Dropdown
open
onToggle={() => {}}
open
>
<Dropdown.Toggle title="Custom range" />
<Dropdown.MenuWrapper style={{ whiteSpace: 'nowrap' }}>
<Dropdown.MenuWrapper
style={{ whiteSpace: 'nowrap' }}
>
<Dropdown.Menu>
<MenuItem eventKey="1d">
Last 24 hours
Expand Down
6 changes: 5 additions & 1 deletion src/Dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,11 @@ class Dropdown extends PureComponent {

if (this.isDropdownMenu(child) || this.isDropdownMenuWrapper(child)) {
return this.renderMenu(child, {
open, pullRight, onClose, onSelect, rootCloseEvent
open,
pullRight,
onClose,
onSelect,
rootCloseEvent
});
}

Expand Down
8 changes: 2 additions & 6 deletions src/DropdownMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ class DropdownMenu extends PureComponent {
};

static defaultProps = {
componentClass: 'div',

// Dropdown
open: false,
pullRight: false
componentClass: 'div'
};

isMenuItem = match(MenuItem);
Expand Down Expand Up @@ -120,7 +116,7 @@ class DropdownMenu extends PureComponent {
className={cx(className, {
[styles.dropdownMenu]: true,
[styles.selected]: activeMenuItems.length > 0,
[styles.pullRight]: pullRight
[styles.pullRight]: !!pullRight
})}
style={style}
>
Expand Down
13 changes: 6 additions & 7 deletions src/DropdownMenuWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ class DropdownMenuWrapper extends PureComponent {
};

static defaultProps = {
componentClass: 'div',

// Dropdown
open: false,
pullRight: false
componentClass: 'div'
};

menu = null; // <DropdownMenu ref={c => this.menu = c} />
Expand Down Expand Up @@ -91,7 +87,8 @@ class DropdownMenuWrapper extends PureComponent {
<Component
{...props}
className={cx(className, {
[styles.dropdownMenuWrapper]: true
[styles.dropdownMenuWrapper]: true,
[styles.pullRight]: !!pullRight
})}
>
{React.Children.map(children, child => {
Expand All @@ -102,7 +99,9 @@ class DropdownMenuWrapper extends PureComponent {
if (this.isDropdownMenu(child)) {
return this.renderMenu(child, {
// Do not pass onClose and rootCloseEvent to the dropdown menu
open, pullRight, onSelect
open,
pullRight,
onSelect
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/dropdown-menu-wrapper.styl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
background-color: #fff;
border: 1px solid #bbbbbb;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);

&.pull-right {
right: 0;
left: auto;
}
}

.dropdown-menu-wrapper > .dropdown-menu {
Expand Down

0 comments on commit ef6c623

Please sign in to comment.