<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>This is hard :(</title>
<style>
/* Styling */
#wrapper {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
border: none;
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(45deg, #f0f0f0, #c0c0c0);
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
button {
all: unset;
cursor: pointer;
display: inline-block;
padding: 1em 2em;
border-radius: 12px;
box-shadow: 0 0 0 2px #333 inset, 0 6px 8px rgba(0, 0, 0, 0.2);
background: linear-gradient(to bottom, #f9f9f9 0%, #d1d1d1 100%);
font-size: 1.5rem;
color: #222;
text-align: center;
user-select: none;
transition: all 0.3s ease;
position: relative;
overflow: hidden;
}
button:hover,
button:focus {
background: linear-gradient(to bottom, #e0e0e0 0%, #a0a0a0 100%);
box-shadow: 0 0 0 2px #555 inset, 0 8px 12px rgba(0, 0, 0, 0.3);
outline: none;
}
#aria-status {
position: absolute;
left: -9999px;
height: 1px;
width: 1px;
overflow: hidden;
}
</style>
</head>
<body>
<!-- Main Doc -->
<main role="main" aria-label="Main content container" tabindex="-1">
<div id="wrapper" role="region" aria-labelledby="btnLabel" aria-describedby="btnDesc">
<section role="group" aria-label="button container">
<h1 id="btnLabel" hidden>Button</h1>
<p id="btnDesc" hidden>Button</p>
<button-wrapper>
<button id="ButtonBtn" role="button" aria-pressed="false" tabindex="0" onclick="handleClick(event)"
onkeydown="handleKeydown(event)" aria-describedby="aria-status" type="button">
Click Me
</button>
</button-wrapper>
<div id="aria-status" role="status" aria-live="polite" aria-atomic="true"></div>
</section>
</div>
</main>
<script>
// Script
class BTNWrapper extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
::slotted(button) {
font-weight: 700;
}
</style>
<slot></slot>
`;
}
}
customElements.define('button-wrapper', BTNWrapper);
function updateAriaStatus(message) {
const status = document.getElementById('aria-status');
status.textContent = '';
setTimeout(() => {
status.textContent = message;
}, 100);
}
function handleClick(event) {
const btn = event.currentTarget;
btn.setAttribute('aria-pressed', btn.getAttribute('aria-pressed') === 'true' ? 'false' : 'true');
updateAriaStatus('Button was clicked');
console.log('Button clicked:', new Date().toLocaleTimeString());
}
function handleKeydown(event) {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
handleClick(event);
}
}
</script>
</body>
</html>
Top comments (0)