-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: associate all inputs with labels via unique IDs (#113)
* feat: surround all inputs by labels for better a11y * reafactor: use unique IDs for html label association * feat: add support for non-react setups * feat: add documentation for useIdWithFallback * fix: run formatter * refactor: import useId directly
- Loading branch information
Showing
5 changed files
with
95 additions
and
60 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useId } from "react" | ||
|
||
/** | ||
* A function to obtain a unique ID. If react is available, this | ||
* is just a wrapper for React.useId(), meaning the ID will be | ||
* consistent across SSR and CSR. Otherwise, it will be a random and | ||
* unique ID on every call. | ||
*/ | ||
export const useIdWithFallback = () => { | ||
try { | ||
return useId() | ||
} catch (e) { | ||
return Math.random().toString(36).substring(2) | ||
} | ||
} |
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