File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -80,22 +80,26 @@ const DownloadButton = ({
8080 const [ isLoading , setIsLoading ] = useState ( false ) ;
8181
8282 const handleClick = async ( e : React . MouseEvent ) => {
83- if ( ! data . lazy ) {
83+ if ( data . disabled ) {
84+ e . preventDefault ( ) ;
85+ e . stopPropagation ( ) ;
8486 return ;
8587 }
8688
87- if ( data . disabled ) {
89+ e . preventDefault ( ) ;
90+
91+ if ( ! data . lazy ) {
92+ downloadByURL ( data . data , data . filename ?? undefined ) ;
8893 return ;
8994 }
9095
91- e . preventDefault ( ) ;
9296 setIsLoading ( true ) ;
9397
9498 try {
9599 const loadedData = await load ( { } ) ;
96100 downloadByURL (
97101 loadedData . data ,
98- loadedData . filename || data . filename || "download" ,
102+ loadedData . filename ?? data . filename ?? undefined ,
99103 ) ;
100104 } catch ( error ) {
101105 toast ( {
@@ -114,9 +118,7 @@ const DownloadButton = ({
114118 return (
115119 < a
116120 href = { data . data }
117- download = { data . filename || true }
118- target = "_blank"
119- rel = "noopener noreferrer"
121+ download = { data . filename ?? "" }
120122 onClick = { handleClick }
121123 className = { buttonVariants ( {
122124 variant : "secondary" ,
Original file line number Diff line number Diff line change @@ -175,10 +175,12 @@ export async function downloadHTMLAsImage(opts: {
175175 }
176176}
177177
178- export function downloadByURL ( url : string , filename : string ) {
178+ export function downloadByURL ( url : string , filename ? : string ) {
179179 const a = document . createElement ( "a" ) ;
180180 a . href = url ;
181- a . download = filename ;
181+ if ( filename ) {
182+ a . download = filename ;
183+ }
182184 a . click ( ) ;
183185 a . remove ( ) ;
184186}
You can’t perform that action at this time.
0 commit comments