fix: clamp negative resources + add tutorial focus trap
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Successful in 9s
Smoke Test / smoke (pull_request) Failing after 20s

- Clamp ops, trust, compute to >= 0 in tick() to prevent negative
  values from Fenrir drain and debuff effects
- Add keyboard focus trap to tutorial overlay for accessibility
  (prevents Tab from escaping the dialog)
- Clean up focus trap handler on tutorial close
This commit is contained in:
Alexander Whitestone
2026-04-21 10:37:33 -04:00
parent d5645fea58
commit 6fb0edeae0
2 changed files with 25 additions and 0 deletions

View File

@@ -208,6 +208,23 @@ function renderTutorialStep(index) {
// Focus the next button so Enter works
const nextBtn = document.getElementById('tutorial-next-btn');
if (nextBtn) nextBtn.focus();
// Focus trap: prevent tabbing outside the tutorial overlay
overlay._focusTrapHandler = function(e) {
if (e.key !== 'Tab') return;
const focusable = overlay.querySelectorAll('button, [href], [tabindex]:not([tabindex="-1"])');
if (focusable.length === 0) return;
const first = focusable[0];
const last = focusable[focusable.length - 1];
if (e.shiftKey && document.activeElement === first) {
e.preventDefault();
last.focus();
} else if (!e.shiftKey && document.activeElement === last) {
e.preventDefault();
first.focus();
}
};
overlay.addEventListener('keydown', overlay._focusTrapHandler);
}
let _tutorialStep = 0;
@@ -236,6 +253,9 @@ document.addEventListener('keydown', function tutorialKeyHandler(e) {
function closeTutorial() {
const overlay = document.getElementById('tutorial-overlay');
if (overlay) {
if (overlay._focusTrapHandler) {
overlay.removeEventListener('keydown', overlay._focusTrapHandler);
}
overlay.style.animation = 'tutorial-fade-in 0.3s ease-in reverse';
setTimeout(() => overlay.remove(), 280);
}