diff --git a/.jules/palette.md b/.jules/palette.md index 2dcd639e..1fbcbf38 100644 --- a/.jules/palette.md +++ b/.jules/palette.md @@ -81,3 +81,7 @@ ## 2024-08-04 - 숫자 입력 필드 빈 문자열 상태 초기화 처리 **학습:** 숫자 입력 필드에서 빈 문자열('')을 입력할 때 브라우저는 이전의 유효하지 않은 상태를 암시적으로 유지하므로, 사용자 정의 검증을 명시적으로 초기화하지 않으면 네이티브 HTML5 유효성 검사가 정상 작동하지 않을 수 있음을 확인했습니다. **실행:** 인라인 검증 스크립트 작성 시 빈 문자열 상태를 별도로 확인하여 this.setCustomValidity('') 및 this.removeAttribute('aria-invalid')를 명시적으로 호출하는 로직을 추가해야 합니다. + +## 2024-09-04 - Improve ARIA state logic on preset buttons +**Learning:** Checking `!e.isTrusted` inside an `input` event listener when an external button click manually dispatches the event (`dispatchEvent`) is unreliable across browsers or testing frameworks, as manual dispatch might not reset `isTrusted` in the way expected, or we might miss normal user typing events properly updating `aria-pressed`. It's better to simply sync the `aria-pressed` state directly without relying on `!e.isTrusted`, ensuring it's always correct whether the change came from typing or clicking. +**Action:** When synchronizing state between an input field and a group of buttons, always rely on the actual value of the input to determine the `aria-pressed` state, rather than trying to detect the source of the event via `e.isTrusted`. diff --git a/saas_web.py b/saas_web.py index 63265e94..b9c4892c 100644 --- a/saas_web.py +++ b/saas_web.py @@ -252,7 +252,7 @@ async def add_security_headers(request: Request, call_next): const presetValue = Number.parseInt(btn.dataset.bytes, 10); btn.setAttribute( 'aria-pressed', - !e.isTrusted && presetValue === val ? 'true' : 'false' + presetValue === val ? 'true' : 'false' ); }); @@ -286,7 +286,7 @@ async def add_security_headers(request: Request, call_next): const presetValue = Number.parseInt(btn.dataset.bytes, 10); btn.setAttribute( 'aria-pressed', - !e.isTrusted && presetValue === val ? 'true' : 'false' + presetValue === val ? 'true' : 'false' ); }); diff --git a/tests/test_saas_web.py b/tests/test_saas_web.py index 3b57e033..a04b6b01 100644 --- a/tests/test_saas_web.py +++ b/tests/test_saas_web.py @@ -368,7 +368,7 @@ def test_get_ui_includes_preset_buttons(self): self.assertIn( "const presetValue = Number.parseInt(btn.dataset.bytes, 10);", html ) - self.assertIn("!e.isTrusted && presetValue === val", html) + self.assertIn("presetValue === val", html) self.assertNotIn("btn.dataset.bytes === this.value", html)