Skip to content

Commit 54ee7ef

Browse files
authored
Allow internal links to be used with carousel items (#973)
1 parent ab1e501 commit 54ee7ef

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/components/carousel/Carousel.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {omit} from 'ramda';
44

55
import RBCarousel from 'react-bootstrap/Carousel';
66

7+
import Link from '../../private/Link';
8+
79
/**
810
* Component for creating Bootstrap carousel. This component is a slideshow
911
* for cycling through a series of content.
@@ -28,12 +30,15 @@ const Carousel = props => {
2830
? item.imgClassName
2931
: 'd-block w-100';
3032

31-
const additionalProps = item.href ? {href: item.href} : {};
33+
const useLink = item.href && true;
34+
const additionalProps = useLink
35+
? {href: item.href, external_link: item.external_link}
36+
: {};
3237

3338
return (
3439
<RBCarousel.Item
3540
key={item.key}
36-
as={item.href ? 'a' : 'div'}
41+
as={item.href ? Link : 'div'}
3742
{...additionalProps}
3843
>
3944
<img
@@ -156,9 +161,21 @@ Carousel.propTypes = {
156161
*/
157162
captionClassName: PropTypes.string,
158163
/**
159-
* Optional hyperlink to add to the item.
164+
* Optional hyperlink to add to the item. Item will be rendered as a
165+
* HTML <a> or as a Dash-style link depending on whether the link is
166+
* deemed to be internal or external. Override this automatic detection
167+
* with the external_link argument.
168+
*/
169+
href: PropTypes.string,
170+
/**
171+
* If true, the browser will treat this as an external link,
172+
* forcing a page refresh at the new location. If false,
173+
* this just changes the location without triggering a page
174+
* refresh. Use this if you are observing dcc.Location, for
175+
* instance. Defaults to true for absolute URLs and false
176+
* otherwise.
160177
*/
161-
href: PropTypes.string
178+
external_link: PropTypes.bool
162179
})
163180
).isRequired,
164181

src/components/dropdownmenu/DropdownMenuItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import {omit} from 'ramda';
44
import RBDropdown from 'react-bootstrap/Dropdown';
55

6-
import Link, {isExternalLink} from '../../private/Link';
6+
import Link from '../../private/Link';
77
import {DropdownMenuContext} from '../../private/DropdownMenuContext';
88

99
/**

0 commit comments

Comments
 (0)