Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add title prop (#97) #180

Merged
merged 1 commit into from
Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export interface Props {
symbol?: FaSymbol
style?: CSSProperties
tabIndex?: number;
title?: string;
}
8 changes: 6 additions & 2 deletions src/components/FontAwesomeIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function normalizeIconArgs(icon) {
}

export default function FontAwesomeIcon(props) {
const { icon: iconArgs, mask: maskArgs, symbol, className } = props
const { icon: iconArgs, mask: maskArgs, symbol, className, title } = props

const iconLookup = normalizeIconArgs(iconArgs)
const classes = objectWithKey('classes', [
Expand All @@ -69,7 +69,8 @@ export default function FontAwesomeIcon(props) {
...classes,
...transform,
...mask,
symbol
symbol,
title
})

if (!renderedIcon) {
Expand Down Expand Up @@ -142,6 +143,8 @@ FontAwesomeIcon.propTypes = {

symbol: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),

title: PropTypes.string,

transform: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
}

Expand All @@ -160,6 +163,7 @@ FontAwesomeIcon.defaultProps = {
size: null,
spin: false,
symbol: false,
title: '',
transform: null
}

Expand Down
13 changes: 13 additions & 0 deletions src/components/__tests__/FontAwesomeIcon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,16 @@ describe('symbol', () => {
expect(spy.mock.calls[0][1].symbol).toBe('coffee-icon')
})
})

describe('title', () => {
test('will not add a title element', () => {
const vm = mount({ icon: faCoffee })
expect(vm.children[0].type).not.toBe('title')
})

test('will add a title element', () => {
const vm = mount({ icon: faCoffee, title: 'Coffee' })
expect(vm.children[0].type).toBe('title')
expect(vm.children[0].children[0]).toBe('Coffee')
})
})
3 changes: 3 additions & 0 deletions src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ function styleToObject(style) {
}

function convert(createElement, element, extraProps = {}) {
if (typeof element === 'string') {
return element
}
const children = (element.children || []).map(
convert.bind(null, createElement)
)
Expand Down