Skip to content

Commit

Permalink
feat(Menu): support activeIndex strings
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Jun 6, 2017
1 parent c836275 commit bae3aaf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/collections/Menu/Menu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface MenuProps {
as?: any;

/** Index of the currently active item. */
activeIndex?: number;
activeIndex?: number | string;

/** A menu may be attached to other content segments. */
attached?: boolean | 'bottom' | 'top';
Expand All @@ -33,7 +33,7 @@ export interface MenuProps {
compact?: boolean;

/** Initial activeIndex value. */
defaultActiveIndex?: number;
defaultActiveIndex?: number | string;

/** A menu can be fixed to a side of its context. */
fixed?: 'left'| 'right'| 'bottom'| 'top';
Expand Down
12 changes: 9 additions & 3 deletions src/collections/Menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ class Menu extends Component {
as: customPropTypes.as,

/** Index of the currently active item. */
activeIndex: PropTypes.number,
activeIndex: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
]),

/** A menu may be attached to other content segments. */
attached: PropTypes.oneOfType([
Expand All @@ -54,7 +57,10 @@ class Menu extends Component {
compact: PropTypes.bool,

/** Initial activeIndex value. */
defaultActiveIndex: PropTypes.number,
defaultActiveIndex: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
]),

/** A menu can be fixed to a side of its context. */
fixed: PropTypes.oneOf(['left', 'right', 'bottom', 'top']),
Expand Down Expand Up @@ -152,7 +158,7 @@ class Menu extends Component {

return _.map(items, (item, index) => MenuItem.create(item, {
defaultProps: {
active: activeIndex === index,
active: parseInt(activeIndex, 10) === index,
index,
},
overrideProps: this.handleItemOverrides,
Expand Down
7 changes: 7 additions & 0 deletions test/specs/collections/Menu/Menu-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ describe('Menu', () => {
.at(1)
.should.have.prop('active', true)
})

it('works as a string', () => {
mount(<Menu items={items} activeIndex={1} />)
.find('MenuItem')
.at(1)
.should.have.prop('active', true)
})
})

describe('items', () => {
Expand Down

0 comments on commit bae3aaf

Please sign in to comment.