Skip to content

Commit 1b90415

Browse files
committed
fix(Aside): deprecate hidden prop, tune displayBreakpoint behaviour
1 parent 1c12c7b commit 1b90415

File tree

3 files changed

+10
-25
lines changed

3 files changed

+10
-25
lines changed

src/Aside.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import classNames from 'classnames';
4-
import { asideMenuCssClasses } from './Shared';
4+
import { asideMenuCssClasses, checkBreakpoint, validBreakpoints } from './Shared';
5+
import toggleClasses from './Shared/toggle-classes';
56

67
const propTypes = {
78
children: PropTypes.node,
89
className: PropTypes.string,
910
display: PropTypes.string,
1011
fixed: PropTypes.bool,
11-
hidden: PropTypes.bool,
1212
isOpen: PropTypes.bool,
1313
offCanvas: PropTypes.bool,
1414
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
@@ -18,7 +18,6 @@ const defaultProps = {
1818
tag: 'aside',
1919
display: '',
2020
fixed: false,
21-
hidden: false,
2221
isOpen: false,
2322
offCanvas: true
2423
};
@@ -28,22 +27,16 @@ class AppAside extends Component {
2827
super(props);
2928

3029
this.isFixed = this.isFixed.bind(this);
31-
this.isHidden = this.isHidden.bind(this);
3230
this.isOffCanvas = this.isOffCanvas.bind(this);
3331
this.displayBreakpoint = this.displayBreakpoint.bind(this);
3432
}
3533

3634
componentDidMount() {
3735
this.isFixed(this.props.fixed);
38-
this.isHidden(this.props.hidden);
3936
this.isOffCanvas(this.props.offCanvas);
4037
this.displayBreakpoint(this.props.display);
4138
}
4239

43-
isHidden(hidden) {
44-
if (hidden) { document.body.classList.add('aside-menu-hidden'); }
45-
}
46-
4740
isFixed(fixed) {
4841
if (fixed) { document.body.classList.add('aside-menu-fixed'); }
4942
}
@@ -53,20 +46,17 @@ class AppAside extends Component {
5346
}
5447

5548
displayBreakpoint(display) {
56-
const cssTemplate = `aside-menu-${display}-show`;
57-
let [cssClass] = asideMenuCssClasses[0];
58-
if (display && asideMenuCssClasses.indexOf(cssTemplate) > -1) {
59-
cssClass = cssTemplate;
49+
if (display && checkBreakpoint(display, validBreakpoints)) {
50+
const cssClass = `aside-menu-${display}-show`
51+
toggleClasses(cssClass, asideMenuCssClasses, true)
6052
}
61-
document.body.classList.add(cssClass);
6253
}
6354

6455
render() {
6556
const { className, children, tag: Tag, ...attributes } = this.props;
6657

6758
delete attributes.display
6859
delete attributes.fixed
69-
delete attributes.hidden
7060
delete attributes.offCanvas
7161
delete attributes.isOpen
7262

src/Aside.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
| prop | default |
44
| ------- | ---------
5-
| children |
5+
| children |
66
| className | `aside-menu`
7-
| display | `sm, md, lg, xl, ""`
7+
| display | `sm, md, lg, xl, ""`
88
| fixed | `false`
9-
| hidden | `false`
9+
| hidden | `false` *deprecated* in v2 as conflicting with HTML5 `hidden` attribute
1010
| isOpen | `false`
1111
| offCanvas | `true`
1212
| tag | `aside`

tests/Aside.test.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,15 @@ configure({ adapter: new Adapter() });
1212

1313
describe('AppAside', () => {
1414
it('renders aside with class="aside-menu"', () => {
15-
expect(render(<AppAside fixed hidden offCanvas display="lg">aside</AppAside>))
15+
expect(render(<AppAside fixed offCanvas display="lg">aside</AppAside>))
1616
.toContain('<aside class="aside-menu">aside</aside>')
1717
});
1818
it('calls componentDidMount', () => {
1919
spy(AppAside.prototype, 'componentDidMount');
2020

21-
const wrapper = mount(<AppAside fixed hidden display="lg" />);
21+
const wrapper = mount(<AppAside fixed />);
2222
expect(AppAside.prototype.componentDidMount.calledOnce).toEqual(true);
2323
});
24-
it('should call isHidden()', () => {
25-
const isHidden = spy(AppAside.prototype, 'isHidden');
26-
shallow(<AppAside />);
27-
expect(isHidden.called).toBe(true);
28-
});
2924
it('should call isOffCanvas()', () => {
3025
const isOffCanvas = spy(AppAside.prototype, 'isOffCanvas');
3126
shallow(<AppAside offCanvas={false}/>);

0 commit comments

Comments
 (0)