TypeScript Lab: Input Naming Assist
Planned
LAB 079 — Semantic HTML
Use available placeholder text when a control lacks an accessible name.
TypeScript Lab: Input Naming Assist
DOM checks can identify unnamed controls while preserving explicit accessible naming.
DOM checks can identify unnamed controls while preserving explicit accessible naming.
Objective & Explanation
What the project should make visible and why the concept matters.Objective
Use available placeholder text when a control lacks an accessible name.
Explanation
DOM checks can identify unnamed controls while preserving explicit accessible naming.
Project Plan
Structure, technologies, data boundary, and source connection.Build Instructions
Build only the focused behavior, then use the visual layer to inspect it.Install TypeScript locally and initialize the compiler configuration.
- Implement only the concept shown in the code example.
- Compile the TypeScript and load the browser page.
Change one input or action and confirm the visible result changes for the expected reason.
Code & Configuration
Starter configuration plus the focused implementation example.document.querySelectorAll("input, select, textarea").forEach(control => {
const placeholder = control.getAttribute("placeholder")?.trim();
if (placeholder && !control.hasAttribute("aria-label")) {
control.setAttribute("aria-label", placeholder);
}
});package.json
{
"type": "module",
"scripts": { "build": "tsc" },
"devDependencies": { "typescript": "^7.0.2" }
}tsconfig.json
{
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"target": "ES2022",
"module": "ES2022",
"lib": ["ES2022", "DOM"],
"strict": true,
"sourceMap": true
},
"include": ["src/**/*.ts"]
}Expected Visual Result
The output is the proof that the concept is working.The browser should visibly demonstrate: use available placeholder text when a control lacks an accessible name.
Data: None