-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added coderabbit js and css suggestions
- Loading branch information
Showing
2 changed files
with
39 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,45 @@ | ||
function toggleFolder(folderId) { | ||
function toggleFolder(folderId, event) { | ||
if (!folderId) { | ||
console.error('Folder ID is required'); | ||
return; | ||
} | ||
|
||
const content = document.getElementById(folderId); | ||
if (!content) { | ||
console.error(`Element with ID ${folderId} not found`); | ||
return; | ||
} | ||
|
||
const folderItem = content.previousElementSibling; | ||
if (!folderItem) { | ||
console.error(`No folder item found for content ${folderId}`); | ||
return; | ||
} | ||
|
||
const isExpanded = folderItem.classList.contains('active'); | ||
|
||
// Update ARIA attributes | ||
folderItem.setAttribute('role', 'button'); | ||
folderItem.setAttribute('aria-expanded', !isExpanded); | ||
folderItem.setAttribute('aria-controls', folderId); | ||
content.setAttribute('role', 'region'); | ||
|
||
// Toggle active state on folder item | ||
folderItem.classList.toggle('active'); | ||
|
||
// Toggle visibility of content | ||
content.classList.toggle('visible'); | ||
|
||
// Prevent event bubbling | ||
event.stopPropagation(); | ||
if (event) { | ||
event.stopPropagation(); | ||
} | ||
} | ||
|
||
// Add keyboard support | ||
document.addEventListener('keydown', (event) => { | ||
if (event.target.hasAttribute('aria-controls') && | ||
(event.key === 'Enter' || event.key === ' ')) { | ||
event.preventDefault(); | ||
toggleFolder(event.target.getAttribute('aria-controls'), event); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters