Skip to content

Commit

Permalink
fix(jsx): changes behavior when download attribute is set to a bool…
Browse files Browse the repository at this point in the history
…ean value (#3094)
  • Loading branch information
oon00b authored Jul 5, 2024
1 parent 28de9b3 commit 72ee808
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/jsx/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const booleanAttributes = [
'default',
'defer',
'disabled',
'download',
'formnovalidate',
'hidden',
'inert',
Expand Down
22 changes: 22 additions & 0 deletions src/jsx/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,28 @@ describe('render to string', () => {
})
})

describe('download attribute', () => {
it('<a download={true}></a> should be rendered as <a download=""></a>', () => {
const template = <a download={true}></a>
expect(template.toString()).toBe('<a download=""></a>')
})

it('<a download={false}></a> should be rendered as <a></a>', () => {
const template = <a download={false}></a>
expect(template.toString()).toBe('<a></a>')
})

it('<a download></a> should be rendered as <a download=""></a>', () => {
const template = <a download></a>
expect(template.toString()).toBe('<a download=""></a>')
})

it('<a download="test"></a> should be rendered as <a download="test"></a>', () => {
const template = <a download='test'></a>
expect(template.toString()).toBe('<a download="test"></a>')
})
})

describe('Function', () => {
it('should be ignored used in on* props', () => {
const onClick = () => {}
Expand Down
4 changes: 2 additions & 2 deletions src/jsx/intrinsic-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export namespace JSX {
type HTMLAttributeAnchorTarget = '_self' | '_blank' | '_parent' | '_top' | string

interface AnchorHTMLAttributes extends HTMLAttributes {
download?: any
download?: string | boolean | undefined
href?: string | undefined
hreflang?: string | undefined
media?: string | undefined
Expand All @@ -194,7 +194,7 @@ export namespace JSX {
interface AreaHTMLAttributes extends HTMLAttributes {
alt?: string | undefined
coords?: string | undefined
download?: any
download?: string | boolean | undefined
href?: string | undefined
hreflang?: string | undefined
media?: string | undefined
Expand Down

0 comments on commit 72ee808

Please sign in to comment.