diff --git a/src/Breadcrumb/Breadcrumb.Component.js b/src/Breadcrumb/Breadcrumb.Component.js index 0e9b7a567..750defddd 100644 --- a/src/Breadcrumb/Breadcrumb.Component.js +++ b/src/Breadcrumb/Breadcrumb.Component.js @@ -1,18 +1,25 @@ +import { Link } from 'react-router-dom'; import React from 'react'; import { Breadcrumb, BreadcrumbItem } from '../'; import { Description, DocsText, DocsTile, Header, Import, Properties, Separator } from '../_playground'; export const BreadcrumbComponent = () => { const breadcrumbHrefCode = ` - - - + + + `; - const breadcrumbLinkCode = ` - - - + const breadcrumbLinkCode = ` + + Link Text + + + Link Text + + + Link Text + `; return ( @@ -43,12 +50,18 @@ export const BreadcrumbComponent = () => { -

Using link (routerLink)

+

Using Link from React Router

- - - + + Link Text + + + Link Text + + + Link Text + {breadcrumbLinkCode} diff --git a/src/Breadcrumb/Breadcrumb.js b/src/Breadcrumb/Breadcrumb.js index 61144fdfe..50f428f28 100644 --- a/src/Breadcrumb/Breadcrumb.js +++ b/src/Breadcrumb/Breadcrumb.js @@ -1,7 +1,6 @@ import classnames from 'classnames'; import PropTypes from 'prop-types'; import React from 'react'; -import { BrowserRouter, Link } from 'react-router-dom'; export const Breadcrumb = ({ children, ...props }) => { return
    {children}
; @@ -15,30 +14,37 @@ Breadcrumb.propDescriptions = { children: 'List item (`BreadcrumbItem`) nodes.' }; -export const BreadcrumbItem = ({ url, link, name, className, ...props }) => { +export const BreadcrumbItem = ({ url, name, className, children, ...props }) => { + const renderLink = () => { + if (!children && url) { + return ( + {name} + ); + } else if (children) { + return React.cloneElement(children, { + 'className': 'fd-breadcrumb__link' + }); + } + }; + const breadcrumbItemClasses = classnames( 'fd-breadcrumb__item', className ); return ( - -
  • - {link && {name}} - {url && {name}} -
  • -
    +
  • + {renderLink()} +
  • ); }; BreadcrumbItem.propTypes = { - name: PropTypes.string.isRequired, - link: PropTypes.string, + name: PropTypes.string, url: PropTypes.string }; BreadcrumbItem.propDescriptions = { - name: 'Localized display text of the link (for either `link` or `url`).', - link: 'Enables use of react-router `Link` component. Path name to be applied to Link\'s `to` prop. Should use either `link` or `url`, but not both.', - url: 'Enables use of `` element. Value to be applied to the anchor\'s `href` attribute. Should use either `link` or `url`, but not both.' + name: 'Text for the internal anchor tag.', + url: 'An anchor tag will be generated and set to the url prop. Name or child text must be provided.' }; diff --git a/src/Breadcrumb/Breadcrumb.test.js b/src/Breadcrumb/Breadcrumb.test.js index 9cf4ca606..d0517dea4 100644 --- a/src/Breadcrumb/Breadcrumb.test.js +++ b/src/Breadcrumb/Breadcrumb.test.js @@ -1,8 +1,8 @@ -import { MemoryRouter } from 'react-router-dom'; import { mount } from 'enzyme'; import React from 'react'; import renderer from 'react-test-renderer'; import { Breadcrumb, BreadcrumbItem } from './Breadcrumb'; +import { Link, MemoryRouter } from 'react-router-dom'; describe('', () => { const defaultBreadCrumb = ( @@ -16,9 +16,13 @@ describe('', () => { const breadCrumbRouterLink = ( - - - + + + Link Text + + + Link Text + );