Skip to content

Commit babfb0e

Browse files
authored
Merge pull request #528 from facultyai/button-download-prop
Add download prop to Button
2 parents 5229f34 + d1c9a3f commit babfb0e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/components/Button.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const Button = props => {
2222
n_clicks,
2323
target,
2424
type,
25+
download,
2526
...otherProps
2627
} = props;
2728

@@ -43,6 +44,7 @@ const Button = props => {
4344
target={useLink ? target : null}
4445
href={disabled ? null : href}
4546
disabled={disabled}
47+
download={useLink ? download : null}
4648
{...omit(['n_clicks_timestamp'], otherProps)}
4749
data-dash-is-loading={
4850
(loading_state && loading_state.is_loading) || undefined
@@ -186,7 +188,12 @@ Button.propTypes = {
186188
* The default behavior of the button. Possible values are: button, reset,
187189
* submit
188190
*/
189-
type: PropTypes.oneOf(['button', 'reset', 'submit'])
191+
type: PropTypes.oneOf(['button', 'reset', 'submit']),
192+
193+
/**
194+
* Indicates that the hyperlink is to be used for downloading a resource.
195+
*/
196+
download: PropTypes.string
190197
};
191198

192199
export default Button;

src/private/Link.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ class Link extends Component {
6868
preOnClick,
6969
target,
7070
href,
71+
download,
7172
...otherProps
7273
} = this.props;
74+
const linkIsExternal = href && isExternalLink(external_link, href);
7375
/**
7476
* ideally, we would use cloneElement however
7577
* that doesn't work with dash's recursive
@@ -78,7 +80,8 @@ class Link extends Component {
7880
return (
7981
<a
8082
href={href}
81-
target={href && isExternalLink(external_link, href) ? target : null}
83+
target={linkIsExternal ? target : null}
84+
download={download && linkIsExternal ? download : null}
8285
{...otherProps}
8386
onClick={e => this.updateLocation(e)}
8487
>
@@ -136,7 +139,9 @@ Link.propTypes = {
136139
*/
137140
preOnClick: PropTypes.func,
138141

139-
target: PropTypes.string
142+
target: PropTypes.string,
143+
144+
download: PropTypes.string
140145
};
141146

142147
Link.defaultProps = {

0 commit comments

Comments
 (0)