Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
Added ability for root element to be either non-semantic html (div) o…
Browse files Browse the repository at this point in the history
…r semantic html (nav).
  • Loading branch information
joeflack4 committed Feb 10, 2018
1 parent 12b2baa commit faafe63
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
24 changes: 19 additions & 5 deletions dist-modules/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,24 @@ var Sidebar = function (_Component) {
}
}

var sideBar = this.props.sideBarElement === 'nav' ? _react2.default.createElement(
'nav',
{ className: this.props.sidebarClassName,
style: sidebarStyle,
ref: this.saveSidebarRef },
this.props.sidebar
) : _react2.default.createElement(
'div',
{ className: this.props.sidebarClassName,
style: sidebarStyle,
ref: this.saveSidebarRef },
this.props.sidebar
);

return _react2.default.createElement(
'div',
rootProps,
_react2.default.createElement(
'div',
{ className: this.props.sidebarClassName, style: sidebarStyle, ref: this.saveSidebarRef },
this.props.sidebar
),
sideBar,
_react2.default.createElement('div', { className: this.props.overlayClassName,
style: overlayStyle,
role: 'presentation',
Expand Down Expand Up @@ -439,6 +449,9 @@ Sidebar.propTypes = {
// Enable/Disable sidebar shadow
shadow: _propTypes2.default.bool,

// if an element other than 'div' is to be rendered as the sidebar root.
sideBarElement: _propTypes2.default.string,

// distance we have to drag the sidebar to toggle open state
dragToggleDistance: _propTypes2.default.number,

Expand All @@ -457,6 +470,7 @@ Sidebar.defaultProps = {
touchHandleWidth: 20,
pullRight: false,
shadow: true,
sideBarElement: 'div',
dragToggleDistance: 30,
onSetOpen: function onSetOpen() {},
styles: {},
Expand Down
22 changes: 19 additions & 3 deletions src/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,23 @@ class Sidebar extends Component {
}
}

const sideBar = this.props.sideBarElement === 'nav'
? <nav className={this.props.sidebarClassName}
style={sidebarStyle}
ref={this.saveSidebarRef}>
{this.props.sidebar}
</nav>
: <div className={this.props.sidebarClassName}
style={sidebarStyle}
ref={this.saveSidebarRef}>
{this.props.sidebar}
</div>;

return (
<div {...rootProps}>
<div className={this.props.sidebarClassName} style={sidebarStyle} ref={this.saveSidebarRef}>
{this.props.sidebar}
</div>

{sideBar}

<div className={this.props.overlayClassName}
style={overlayStyle}
role="presentation"
Expand Down Expand Up @@ -386,6 +398,9 @@ Sidebar.propTypes = {
// Enable/Disable sidebar shadow
shadow: PropTypes.bool,

// if an element other than 'div' is to be rendered as the sidebar root.
sideBarElement: PropTypes.string,

// distance we have to drag the sidebar to toggle open state
dragToggleDistance: PropTypes.number,

Expand All @@ -404,6 +419,7 @@ Sidebar.defaultProps = {
touchHandleWidth: 20,
pullRight: false,
shadow: true,
sideBarElement: 'div',
dragToggleDistance: 30,
onSetOpen: () => {},
styles: {},
Expand Down

0 comments on commit faafe63

Please sign in to comment.