Skip to content

Commit

Permalink
fix: 스크린 리더가 snackbar를 읽도록 한다
Browse files Browse the repository at this point in the history
  • Loading branch information
airman5573 committed Oct 10, 2022
1 parent 5cbc1ec commit 3d5be27
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/SnackbarManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class SnackbarManager {
this.#check();
this.#element.classList.add('show');
this.#element.textContent = message;
// this.#element.setAttribute('aria-live', 'assertive');
this.#timer && clearTimeout(this.#timer);
this.#timer = setTimeout(() => {
this.hide();
Expand All @@ -30,8 +29,8 @@ class SnackbarManager {

hide() {
this.#check();
// this.#element.setAttribute('aria-live', 'off');
this.#element.classList.remove('show');
this.#element.textContent = '';
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import './style/style.scss';
import { $ } from './util';

const MAX_RESERVABLE_ADULT_PASSENGER_COUNT = 3;
const ERROR_MESSAGE = {
OVER_RESERVABLE_ADULT: '인원수는 0명에서 3명까지만 가능합니다',
};

document.addEventListener('DOMContentLoaded', () => {
const $adultPassengerField = $('.adult-passenger-field');
Expand All @@ -28,13 +31,12 @@ document.addEventListener('DOMContentLoaded', () => {

const nextValue = value + step;
if (nextValue < 0 || nextValue > 3) {
snackbarManager.show('인원수는 0명에서 3명까지만 가능합니다');
snackbarManager.show(ERROR_MESSAGE.OVER_RESERVABLE_ADULT);
return;
}

$adultPassengerSpinInput.value = Math.max(0, Math.min(MAX_RESERVABLE_ADULT_PASSENGER_COUNT, nextValue));
$adultPassengerSpinAriaLiveMessage.textContent = `성인 승객 추가 ${$adultPassengerSpinInput.value}`;
// $adultPassengerSpinAriaLiveMessage.setAttribute('aria-live', 'assertive');
});

$adultPassengerSpinInput.addEventListener('input', e => {
Expand All @@ -52,20 +54,19 @@ document.addEventListener('DOMContentLoaded', () => {
if (target.value < Number(min)) {
isProperRange = false;
target.value = min;
snackbarManager.show('인원수는 0명에서 3명까지만 가능합니다');
snackbarManager.show(ERROR_MESSAGE.OVER_RESERVABLE_ADULT);
}
}
if (max !== null) {
if (target.value > Number(max)) {
isProperRange = false;
snackbarManager.show('인원수는 0명에서 3명까지만 가능합니다');
snackbarManager.show(ERROR_MESSAGE.OVER_RESERVABLE_ADULT);
target.value = max;
}
}

if (isProperRange) {
$adultPassengerSpinAriaLiveMessage.textContent = `성인 승객 추가 ${target.value}`;
// $adultPassengerSpinAriaLiveMessage.setAttribute('aria-live', 'assertive');
}
});
});

0 comments on commit 3d5be27

Please sign in to comment.