Skip to content

Commit

Permalink
add elementAttributes to navpill and navpills. (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcocchia authored Oct 10, 2017
1 parent 9558840 commit 804db52
Show file tree
Hide file tree
Showing 6 changed files with 335 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/NavigationPills/NavigationPill.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ const NavigationPill = props => {
}

return (
<li style={styles.container}>
<li
style={styles.container}
{ ...props.elementAttributes }
>
<a
href={props.path || '#'}
data-bypass={true}
Expand All @@ -70,6 +73,9 @@ const NavigationPill = props => {
}

NavigationPill.propTypes = {
/** Any additonal props to add to the element (e.g. data attributes). */
elementAttributes: PropTypes.object,

/** determines wether or not active styles are applied */
isActive: PropTypes.bool,
/** Callback function called after pill click
Expand All @@ -86,6 +92,7 @@ NavigationPill.propTypes = {
}

NavigationPill.defaultProps = {
elementAttributes: {},
isActive: false
}

Expand Down
8 changes: 8 additions & 0 deletions src/components/NavigationPills/NavigationPills.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const NavigationPills = props => {
<div
style={wrapperStyles}
ref='pillsTrack'
{ ...props.elementAttributes }
>
{renderLabel()}
<ul style={pillsContainerStyles}>
Expand All @@ -62,6 +63,9 @@ const NavigationPills = props => {
}

NavigationPills.propTypes = {
/** Any additonal props to add to the element (e.g. data attributes). */
elementAttributes: PropTypes.object,

/** array of pill objects */
pills: PropTypes.array,
/** Callback function called after pill click
Expand All @@ -75,4 +79,8 @@ NavigationPills.propTypes = {
activePill: PropTypes.string
}

NavigationPills.defaultProps = {
elementAttributes: {}
}

export default Radium(NavigationPills)
10 changes: 10 additions & 0 deletions src/components/NavigationPills/__tests__/NavigationPill.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ it('renders href pill correctly', () => {
).toJSON()
expect(tree).toMatchSnapshot()
})

it('renders element attributes on pill correctly', () => {
const tree = renderer.create(
<NavigationPill
text={'pill with attributes'}
elementAttributes={{ ariaLabel:'this is an aria label', role:'tab'}}
/>
).toJSON()
expect(tree).toMatchSnapshot()
})
17 changes: 17 additions & 0 deletions src/components/NavigationPills/__tests__/NavigationPills.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ it('renders NavigationPills without pills correctly', () => {
expect(tree).toMatchSnapshot()
})

it('renders NavigationPills with elementAttributes correctly', () => {
const tree = renderer.create(
<StyleRoot>
<div>
<NavigationPills
pills={ testPills }
onPillClick={(e, pill) => { console.log(pill) }}
label={'Filter by'}
activePill={'dom2'}
elementAttributes={{ ariaLabel:'this is an aria label', role:'tabs'}}
/>
</div>
</StyleRoot>
).toJSON()
expect(tree).toMatchSnapshot()
})

it('it handles onPillClick correctly', () => {
const onPillClick = spy()
const Pills = mount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,45 @@ exports[`renders active pill correctly 1`] = `
</li>
`;

exports[`renders element attributes on pill correctly 1`] = `
<li
ariaLabel="this is an aria label"
data-radium={true}
role="tab"
style={
Object {
"display": "inline-block",
}
}
>
<a
data-bypass={true}
data-radium={true}
href="#"
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
style={
Object {
"backgroundColor": "#F7F7F7",
"borderRadius": "24px",
"color": "#43B02A",
"display": "block",
"fontSize": "14px",
"lineHeight": "1.2",
"margin": "0 4px",
"padding": "12px 16px",
"transition": "background-color 150ms ease-in-out",
}
}
>
pill with attributes
</a>
</li>
`;

exports[`renders href pill correctly 1`] = `
<li
data-radium={true}
Expand Down
Loading

0 comments on commit 804db52

Please sign in to comment.