-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add attribute and attribute bindings (#7075)
# Pull Request ## 📖 Description This change adds logic for converting: - child nodes into strings - attributes into strings - attribute bindings (not inclusive of boolean attributes, events, or properties which will be separate PRs) ## ✅ Checklist ### General <!--- Review the list and put an x in the boxes that apply. --> - [ ] I have included a change request file using `$ npm run change` - [x] I have added tests for my changes. - [x] I have tested my changes. - [x] I have updated the project documentation to reflect my changes. - [x] I have read the [CONTRIBUTING](https://github.com/microsoft/fast/blob/main/CONTRIBUTING.md) documentation and followed the [standards](https://github.com/microsoft/fast/blob/main/CODE_OF_CONDUCT.md#our-standards) for this project.
- Loading branch information
Showing
11 changed files
with
223 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/web-components/fast-btr/src/fixtures/attribute/attribute.fixture.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en-US"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title></title> | ||
</head> | ||
<body> | ||
<test-element type="checkbox"> | ||
<template shadowrootmode="open"><input type="checkbox" disabled></template> | ||
</test-element> | ||
<f-template name="test-element"> | ||
<template><input type="{{type}}" disabled></template> | ||
</f-template> | ||
<script type="module" src="/attribute/main.js"></script> | ||
</body> | ||
</html> |
1 change: 1 addition & 0 deletions
1
packages/web-components/fast-btr/src/fixtures/attribute/attribute.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<input type="{{type}}" disabled> |
3 changes: 3 additions & 0 deletions
3
packages/web-components/fast-btr/src/fixtures/attribute/attribute.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "checkbox" | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/web-components/fast-btr/src/fixtures/attribute/attribute.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
test.describe("f-template", async () => { | ||
test("create a non-binding attribute", async ({ page }) => { | ||
await page.goto("/attribute"); | ||
|
||
const customElement = page.locator("test-element"); | ||
const customElementInput = customElement.locator("input"); | ||
await expect(customElementInput).toHaveAttribute("disabled"); | ||
}); | ||
test("create an attribute binding", async ({ page }) => { | ||
await page.goto("/attribute"); | ||
|
||
const customElement = page.locator("test-element"); | ||
|
||
await expect(customElement).toHaveAttribute("type", "checkbox"); | ||
await expect(customElement.locator("input[type='checkbox']")).toHaveCount(1); | ||
|
||
await page.evaluate(() => { | ||
const customElement = document.getElementsByTagName("test-element"); | ||
customElement.item(0)?.setAttribute("type", "radio"); | ||
}); | ||
|
||
await expect(customElement).toHaveAttribute("type", "radio"); | ||
await expect(customElement.locator("input[type='radio']")).toHaveCount(1); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
packages/web-components/fast-btr/src/fixtures/attribute/main.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { TemplateElement } from "@microsoft/fast-btr"; | ||
import { attr, FASTElement } from "@microsoft/fast-element"; | ||
|
||
class TestElement extends FASTElement { | ||
@attr | ||
type: string = "radio"; | ||
} | ||
TestElement.define({ | ||
name: "test-element", | ||
}); | ||
|
||
TemplateElement.define({ | ||
name: "f-template", | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/web-components/fast-btr/src/fixtures/attribute/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
import { merge } from "webpack-merge"; | ||
import config from "../../../webpack.common.config.js"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.resolve(path.dirname(__filename), "./"); | ||
|
||
export default merge(config, { | ||
entry: path.resolve(__dirname, "./main.ts"), | ||
output: { | ||
filename: "main.js", | ||
path: path.resolve(__dirname, "../../../server/dist/attribute"), | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters