Skip to content

Commit 2a8bffb

Browse files
gergely-nagyTheSharpieOne
authored andcommitted
feat(NavItem): add active prop to NavItem (#688)
Closes #678
1 parent afd3581 commit 2a8bffb

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

docs/lib/Components/NavsPage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export default class NavssPage extends React.Component {
4646
<pre>
4747
<PrismCode className="language-jsx">
4848
{`NavItem.propTypes = {
49-
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
49+
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
50+
active: PropTypes.bool,
5051
// pass in custom element to use
5152
}`}
5253
</PrismCode>

src/NavItem.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { mapToCssModules } from './utils';
55

66
const propTypes = {
77
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
8+
active: PropTypes.bool,
89
className: PropTypes.string,
910
cssModule: PropTypes.object,
1011
};
@@ -17,13 +18,15 @@ const NavItem = (props) => {
1718
const {
1819
className,
1920
cssModule,
21+
active,
2022
tag: Tag,
2123
...attributes
2224
} = props;
2325

2426
const classes = mapToCssModules(classNames(
2527
className,
26-
'nav-item'
28+
'nav-item',
29+
active ? 'active' : false
2730
), cssModule);
2831

2932
return (

src/__tests__/NavItem.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ describe('NavItem', () => {
2727
expect(wrapper.hasClass('extra')).toBe(true);
2828
expect(wrapper.hasClass('nav-item')).toBe(true);
2929
});
30+
31+
it('should render active class', () => {
32+
const wrapper = shallow(<NavItem active />);
33+
34+
expect(wrapper.hasClass('active')).toBe(true);
35+
});
3036
});

0 commit comments

Comments
 (0)