-
Notifications
You must be signed in to change notification settings - Fork 854
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Déplacement des commits depuis main vers Checkout
- Loading branch information
Showing
2 changed files
with
66 additions
and
4 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,30 @@ | ||
// Ce fichier est une implémentation du problème de base | ||
// Il génère une erreur "infinite depth" | ||
// Pour tester le problème, il faut renommer le fichier en page.tsx | ||
|
||
'use client'; | ||
|
||
import * as React from 'react'; | ||
import * as Checkbox from '@radix-ui/react-checkbox'; | ||
|
||
export default function Page() { | ||
// État (booléen) associé à la checkbox et au div | ||
const [isChecked, setIsChecked] = React.useState(false); | ||
|
||
// Fonction pour alterner l’état de la checkbox | ||
const handleCheckedChange = (newChecked: boolean) => { | ||
console.log('Checkbox checked:', newChecked); // Affiche l'état dans la console | ||
setIsChecked(newChecked); | ||
}; | ||
|
||
return ( | ||
<form> | ||
<div onClick={() => setIsChecked((prev) => !prev)}> {/* Alterne l’état*/} | ||
<Checkbox.Root checked={isChecked} onCheckedChange={handleCheckedChange}> {/* Associe l'état de la checkbox et la fonction d'inversion de l'état*/} | ||
[ <Checkbox.Indicator>✔</Checkbox.Indicator> ] | ||
</Checkbox.Root> | ||
<span>test</span> | ||
</div> | ||
</form> | ||
); | ||
} |
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,10 +1,42 @@ | ||
// Ce fichier est une implémentation de la solution que nous proposons | ||
// Il dissocie l'état de la checkbox et du div | ||
// Le problème "infinite depth" est résolu tout en laissant le div cliquable | ||
|
||
'use client'; | ||
|
||
import * as React from 'react'; | ||
import * as Checkbox from '@radix-ui/react-checkbox'; | ||
|
||
export default function Page() { | ||
// État pour le div | ||
const [isDivChecked, setIsDivChecked] = React.useState(false); | ||
|
||
// État pour la case à cocher | ||
const [isCheckboxChecked, setIsCheckboxChecked] = React.useState(false); | ||
|
||
// Fonction pour alterner l’état du div | ||
const handleDivClick = () => { | ||
console.log('Div clicked:', !isDivChecked); | ||
setIsDivChecked((prev) => !prev); | ||
}; | ||
|
||
// Fonction pour alterner l’état de la checkbox | ||
const handleCheckedChange = (newChecked: boolean) => { | ||
console.log('Checkbox checked:', newChecked); | ||
setIsCheckboxChecked(newChecked); | ||
}; | ||
|
||
return ( | ||
<Checkbox.Root> | ||
[ <Checkbox.Indicator>✔</Checkbox.Indicator> ] | ||
</Checkbox.Root> | ||
<form> | ||
<div onClick={handleDivClick}> {/* Alterne l’état du div */} | ||
<Checkbox.Root | ||
checked={isCheckboxChecked} | ||
onCheckedChange={handleCheckedChange} // Alterne l’état de la checkbox | ||
> | ||
[ <Checkbox.Indicator>✔</Checkbox.Indicator> ] | ||
</Checkbox.Root> | ||
<span>test</span> | ||
</div> | ||
</form> | ||
); | ||
} | ||
} |