-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce aria-current service (#5599)
- Loading branch information
Showing
20 changed files
with
213 additions
and
211 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
27 changes: 27 additions & 0 deletions
27
packages/components/src/components/link/ariaCurrentService.ts
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
type LocationChangeCallback = (location: string) => void; | ||
export type UnsubscribeFunction = () => void; | ||
|
||
let currentLocation: string | undefined; | ||
const subscribers: Array<LocationChangeCallback> = []; | ||
|
||
export const setCurrentLocation = (location: string) => { | ||
currentLocation = location; | ||
subscribers.forEach((subscriber) => { | ||
subscriber(location); | ||
}); | ||
}; | ||
|
||
export const onLocationChange = (callback: LocationChangeCallback, eager = true): UnsubscribeFunction => { | ||
if (eager && typeof currentLocation === 'string') { | ||
callback(currentLocation); | ||
} | ||
subscribers.push(callback); | ||
|
||
// unsubscribe function | ||
return () => { | ||
const index = subscribers.indexOf(callback); | ||
if (index >= 0) { | ||
subscribers.splice(index, 1); | ||
} | ||
}; | ||
}; |
Oops, something went wrong.