fix: clamp negative resources + add tutorial focus trap
- 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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user