Skip to content

Commit

Permalink
feat(Dropdown): Add backwards compatible left & right
Browse files Browse the repository at this point in the history
Maps to start & end
  • Loading branch information
gthomas-appfolio authored and phwebi committed Oct 27, 2021
1 parent 7417984 commit f8b415f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/Dropdown.js
Expand Up @@ -11,7 +11,7 @@ import { mapToCssModules, omit, keyCodes, tagPropType } from './utils';
const propTypes = {
a11y: PropTypes.bool,
disabled: PropTypes.bool,
direction: PropTypes.oneOf(['up', 'down', 'start', 'end']),
direction: PropTypes.oneOf(['up', 'down', 'start', 'end', 'left', 'right']),
group: PropTypes.bool,
isOpen: PropTypes.bool,
nav: PropTypes.bool,
Expand Down Expand Up @@ -269,13 +269,15 @@ class Dropdown extends React.Component {

const classes = mapToCssModules(classNames(
className,
direction !== 'down' && `drop${direction}`,
nav && active ? 'active' : false,
setActiveFromChild && subItemIsActive ? 'active' : false,
{
'btn-group': group,
[`btn-group-${size}`]: !!size,
dropdown: !group,
dropup: direction === 'up',
dropstart: direction === 'start' || direction === 'left',
dropend: direction === 'end' || direction === 'right',
show: isOpen,
'nav-item': nav
}
Expand Down
10 changes: 7 additions & 3 deletions src/DropdownMenu.js
Expand Up @@ -4,7 +4,7 @@ import ReactDOM from 'react-dom';
import classNames from 'classnames';
import { Popper } from 'react-popper';
import { DropdownContext } from './DropdownContext';
import { mapToCssModules, tagPropType, targetPropType, getTarget } from './utils';
import { mapToCssModules, tagPropType, targetPropType, getTarget, deprecated } from './utils';

const propTypes = {
tag: tagPropType,
Expand All @@ -18,6 +18,7 @@ const propTypes = {
persist: PropTypes.bool,
strategy: PropTypes.string,
container: targetPropType,
right: deprecated(PropTypes.bool, 'Please use "end" instead.'),
};

const defaultProps = {
Expand All @@ -28,6 +29,8 @@ const defaultProps = {

const directionPositionMap = {
up: 'top',
left: 'left',
right: 'right',
start: 'left',
end: 'right',
down: 'bottom',
Expand All @@ -48,6 +51,7 @@ class DropdownMenu extends React.Component {
cssModule,
dark,
end,
right,
tag,
flip,
modifiers,
Expand All @@ -62,7 +66,7 @@ class DropdownMenu extends React.Component {
'dropdown-menu',
{
'dropdown-menu-dark': dark,
'dropdown-menu-end': end,
'dropdown-menu-end': end || right,
show: this.context.isOpen,
}
), cssModule);
Expand All @@ -72,7 +76,7 @@ class DropdownMenu extends React.Component {
if (persist || (this.context.isOpen && !this.context.inNavbar)) {

const position1 = directionPositionMap[this.context.direction] || 'bottom';
const position2 = end ? 'end' : 'start';
const position2 = (end || right) ? 'end' : 'start';
const poperPlacement = `${position1}-${position2}`;
const poperModifiers = [
...modifiers,
Expand Down

0 comments on commit f8b415f

Please sign in to comment.