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

ARIA #69

Merged
merged 4 commits into from
Jan 4, 2024
Merged

ARIA #69

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
12 changes: 10 additions & 2 deletions jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@ namespace JSXInternal {
}[keyof T]

export type HtmlElementAttributes<T> = {
[Property in WritableKeys<T> as T[Property] extends string | number
[Property in WritableKeys<T> as T[Property] extends
| string
| number
| null
| undefined
? Property
: never]?: T[Property]
}

export type HtmlElementAttributesBind<T> = {
[Property in WritableKeys<T> as T[Property] extends string | number
[Property in WritableKeys<T> as T[Property] extends
| string
| number
| null
| undefined
? Property
: never]?: Observable<T[Property]>
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "module",
"name": "butterfloat",
"version": "1.1.0",
"version": "1.2.0",
"description": "Knockout-inspired view engine for RxJS with TSX",
"homepage": "https://worldmaker.net/butterfloat/",
"repository": "github:WorldMaker/butterfloat",
Expand Down
16 changes: 15 additions & 1 deletion static-dom.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('static-dom', () => {
})

it('builds a single element with dataset data- attributes', () => {
const desc = <div data-test="something" data-funkyThing="music" />
const desc = <div data-test="something" data-funky-thing="music" />
equal(desc.type, 'element')
const test = buildElement(desc, document)
equal(test.tagName, 'DIV')
Expand All @@ -40,6 +40,20 @@ describe('static-dom', () => {
test.remove()
})

it('builds a single element with aria- attributes', () => {
const desc = (
<div role="navigation" aria-label="something" aria-expanded="true" />
)
equal(desc.type, 'element')
const test = buildElement(desc, document)
equal(test.tagName, 'DIV')
equal(test.role, 'navigation')
equal(test.getAttribute('aria-label'), 'something')
equal(test.getAttribute('aria-expanded'), 'true')

test.remove()
})

it('builds a single label with dataset for attribute', () => {
const desc = <label for="example" />
equal(desc.type, 'element')
Expand Down
5 changes: 3 additions & 2 deletions static-dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export function buildElement(
) {
const element = document.createElement(description.element)
for (const [key, value] of Object.entries(description.attributes)) {
if (key.startsWith('data-')) {
element.dataset[key.replace(/^data-/, '')] = value as string | undefined
if (key.includes('-')) {
// for example: aria- and data-
element.setAttribute(key, (value ?? '').toString())
} else if (key === 'class') {
element.className = value as string
} else if (key === 'for') {
Expand Down