-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fixed] management of aria-hidden attribute decoupled from the manage…
…ment of the body open class
- Loading branch information
Showing
5 changed files
with
137 additions
and
45 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
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
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
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,20 +1,35 @@ | ||
import * as refCount from "./refCount"; | ||
const classListMap = {}; | ||
|
||
export function add(bodyClass) { | ||
// Increment class(es) on refCount tracker and add class(es) to body | ||
const addClassToMap = className => { | ||
// Set variable and default if none | ||
if (!classListMap[className]) { | ||
classListMap[className] = 0; | ||
} | ||
classListMap[className] += 1; | ||
return className; | ||
}; | ||
|
||
const removeClassFromMap = className => { | ||
if (classListMap[className]) { | ||
classListMap[className] -= 1; | ||
} | ||
return className; | ||
}; | ||
|
||
const add = bodyClass => { | ||
bodyClass | ||
.split(" ") | ||
.map(refCount.add) | ||
.map(addClassToMap) | ||
.forEach(className => document.body.classList.add(className)); | ||
} | ||
}; | ||
|
||
export function remove(bodyClass) { | ||
const classListMap = refCount.get(); | ||
// Decrement class(es) from the refCount tracker | ||
// and remove unused class(es) from body | ||
const remove = bodyClass => { | ||
// Remove unused class(es) from body | ||
bodyClass | ||
.split(" ") | ||
.map(refCount.remove) | ||
.map(removeClassFromMap) | ||
.filter(className => classListMap[className] === 0) | ||
.forEach(className => document.body.classList.remove(className)); | ||
} | ||
}; | ||
|
||
export { add, remove }; |
This file was deleted.
Oops, something went wrong.