Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jsx): changes behavior when download attribute is set to a boolean value. #3094

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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