Skip to content

Commit

Permalink
Allow internal links to be used with carousel items (#973)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcbegley authored Sep 4, 2023
1 parent ab1e501 commit 54ee7ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions src/components/carousel/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {omit} from 'ramda';

import RBCarousel from 'react-bootstrap/Carousel';

import Link from '../../private/Link';

/**
* Component for creating Bootstrap carousel. This component is a slideshow
* for cycling through a series of content.
Expand All @@ -28,12 +30,15 @@ const Carousel = props => {
? item.imgClassName
: 'd-block w-100';

const additionalProps = item.href ? {href: item.href} : {};
const useLink = item.href && true;
const additionalProps = useLink
? {href: item.href, external_link: item.external_link}
: {};

return (
<RBCarousel.Item
key={item.key}
as={item.href ? 'a' : 'div'}
as={item.href ? Link : 'div'}
{...additionalProps}
>
<img
Expand Down Expand Up @@ -156,9 +161,21 @@ Carousel.propTypes = {
*/
captionClassName: PropTypes.string,
/**
* Optional hyperlink to add to the item.
* Optional hyperlink to add to the item. Item will be rendered as a
* HTML <a> or as a Dash-style link depending on whether the link is
* deemed to be internal or external. Override this automatic detection
* with the external_link argument.
*/
href: PropTypes.string,
/**
* If true, the browser will treat this as an external link,
* forcing a page refresh at the new location. If false,
* this just changes the location without triggering a page
* refresh. Use this if you are observing dcc.Location, for
* instance. Defaults to true for absolute URLs and false
* otherwise.
*/
href: PropTypes.string
external_link: PropTypes.bool
})
).isRequired,

Expand Down
2 changes: 1 addition & 1 deletion src/components/dropdownmenu/DropdownMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import {omit} from 'ramda';
import RBDropdown from 'react-bootstrap/Dropdown';

import Link, {isExternalLink} from '../../private/Link';
import Link from '../../private/Link';
import {DropdownMenuContext} from '../../private/DropdownMenuContext';

/**
Expand Down

0 comments on commit 54ee7ef

Please sign in to comment.