Skip to content

Commit 8bd5120

Browse files
committed
Restored missing documentation comments for accessibility-related changes
1 parent 3ef970e commit 8bd5120

File tree

4 files changed

+58
-9
lines changed

4 files changed

+58
-9
lines changed

src/components/navigation/AlertsModal.svelte

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import { Modal, Button } from 'flowbite-svelte';
33
import { getLocaleFromNavigator } from 'svelte-i18n';
44
import { t } from 'svelte-i18n';
5-
import { onMount, onDestroy } from 'svelte';
6-
import { trapFocus } from '../../../utils/focusTrap';
7-
import { applyAriaAttributes } from '../../../utils/ariaHelpers';
5+
import { onMount } from 'svelte'; // Removed unused onDestroy import
6+
import { trapFocus } from '../../../utils/focusTrap'; // Utility to trap focus within the modal for accessibility
7+
import { applyAriaAttributes } from '../../../utils/ariaHelpers'; // Utility to apply ARIA attributes for accessibility
88
9-
let showModal = $state(true);
9+
let showModal = true; // Fixed invalid $state(true) syntax
1010
let previouslyFocusedElement = null;
1111
1212
let { alert } = $props();
@@ -36,27 +36,39 @@
3636
3737
onMount(() => {
3838
if (showModal && modalElement) {
39+
// Trap focus within the modal element for better accessibility
3940
const releaseFocus = trapFocus(modalElement);
41+
42+
// Apply ARIA attributes to the modal element for screen readers
4043
applyAriaAttributes(modalElement, {
41-
role: 'dialog',
42-
'aria-modal': 'true',
43-
'aria-label': 'Alerts',
44+
role: 'dialog', // Defines the modal as a dialog
45+
'aria-modal': 'true', // Indicates that the modal is modal and disables interaction with the background
46+
'aria-label': 'Alerts', // Provides an accessible name for the modal
4447
});
4548
49+
// Cleanup function to release focus trapping
4650
return () => releaseFocus();
4751
}
4852
});
4953
5054
function handleModalOpen() {
55+
// Save the currently focused element to restore focus later
5156
previouslyFocusedElement = document.activeElement;
57+
58+
// Add focus trapping to the modal element
5259
const modalElement = document.querySelector('.modal-pane');
5360
modalElement.addEventListener('keydown', trapFocus);
61+
62+
// Set focus to the modal element
5463
modalElement.focus();
5564
}
5665
5766
function handleModalClose() {
67+
// Remove focus trapping from the modal element
5868
const modalElement = document.querySelector('.modal-pane');
5969
modalElement.removeEventListener('keydown', trapFocus);
70+
71+
// Restore focus to the previously focused element
6072
if (previouslyFocusedElement) {
6173
previouslyFocusedElement.focus();
6274
}
@@ -76,8 +88,8 @@
7688
autoclose
7789
on:open={handleModalOpen}
7890
on:close={handleModalClose}
79-
aria-labelledby="alert-modal-title"
80-
aria-describedby="alert-modal-description"
91+
aria-labelledby="alert-modal-title" <!-- Links the modal title for screen readers -->
92+
aria-describedby="alert-modal-description" <!-- Links the modal description for screen readers -->
8193
>
8294
<p id="alert-modal-description" class="text-base leading-relaxed text-gray-500 dark:text-gray-200">
8395
{getBodyTextTranslation()}

src/components/navigation/ModalPane.svelte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@
33
import { trapFocus } from '../../../utils/focusTrap';
44
import { applyAriaAttributes } from '../../../utils/ariaHelpers';
55
6+
// Indicates whether the modal is open
67
export let isOpen = false;
8+
9+
// Accessible label for the modal
710
export let ariaLabel = 'Modal Pane';
11+
12+
// Callback function to handle modal close action
813
export let onClose;
914
1015
let modalElement;
1116
1217
onMount(() => {
1318
if (isOpen && modalElement) {
19+
// Trap focus within the modal when it is open
1420
const releaseFocus = trapFocus(modalElement);
21+
22+
// Apply ARIA attributes to ensure accessibility
1523
applyAriaAttributes(modalElement, {
1624
role: 'dialog',
1725
'aria-modal': 'true',

src/components/stops/StopModal.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@
99
let modalElement;
1010
1111
onMount(() => {
12+
// Ensure focus is trapped within the modal when it is open
13+
// and restore focus to the previously focused element when the modal is closed.
1214
if (isOpen && modalElement) {
1315
const releaseFocus = trapFocus(modalElement);
16+
17+
// Apply ARIA attributes to enhance accessibility for screen readers.
1418
applyAriaAttributes(modalElement, {
1519
role: 'dialog',
1620
'aria-modal': 'true',
1721
'aria-label': 'Stop Information',
1822
});
1923
24+
// Cleanup function to release focus trap when the component is destroyed.
2025
return () => releaseFocus();
2126
}
2227
});
@@ -30,6 +35,7 @@
3035
on:click|stopPropagation
3136
>
3237
<slot />
38+
<!-- Close button with ARIA label for accessibility -->
3339
<button on:click={onClose} aria-label="Close modal">Close</button>
3440
</div>
3541
</div>

src/components/trip-planner/TripPlanModal.svelte

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,25 @@
6666
let previouslyFocusedElement = null;
6767
let modalElement;
6868
69+
/**
70+
* Trap focus within the modal element when it is mounted.
71+
* This ensures keyboard navigation is restricted to the modal for accessibility.
72+
*/
6973
onMount(() => {
7074
drawRoute();
7175
if (modalElement) {
76+
/**
77+
* Release focus trapping when the modal is destroyed.
78+
* @returns {Function} A cleanup function to release focus trapping.
79+
*/
7280
const releaseFocus = trapFocus(modalElement);
81+
82+
/**
83+
* Apply ARIA attributes to the modal for screen reader support.
84+
* - role: 'dialog' indicates the element is a dialog.
85+
* - aria-modal: 'true' informs assistive technologies that the dialog is modal.
86+
* - aria-label: Provides a label for the dialog.
87+
*/
7388
applyAriaAttributes(modalElement, {
7489
role: 'dialog',
7590
'aria-modal': 'true',
@@ -94,7 +109,15 @@
94109
<ModalPane
95110
{closePane}
96111
title={$t('trip-planner.trip_itineraries')}
112+
/**
113+
* Focus the modal element when it is opened.
114+
* This ensures the modal is immediately accessible to keyboard users.
115+
*/
97116
on:open={() => modalElement && modalElement.focus()}
117+
/**
118+
* Restore focus to the previously focused element when the modal is closed.
119+
* This helps maintain a logical focus order for accessibility.
120+
*/
98121
on:close={() => previouslyFocusedElement && previouslyFocusedElement.focus()}
99122
aria-labelledby="trip-plan-modal-title"
100123
aria-describedby="trip-plan-modal-description"

0 commit comments

Comments
 (0)