Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Mieux gérer les valeurs acceptées d'isDisabled des Checkbox/Radio #638

Merged
merged 8 commits into from
May 17, 2024

Conversation

yannbertrand
Copy link
Member

@yannbertrand yannbertrand commented May 13, 2024

🎄 Problème

Pour le moment on peut se retrouver avec aria-disabled="" selon ce qu'on passe au composant. L'attribut aria-disabled avec une valeur autre que "true" ne considère pas l'input comme "disabled" pour VoiceOver qui n'énonce pas "dimmed checkbox". C'est trompeur pour l'usager.

🎁 Proposition

S'assurer de bien transmettre la valeur "true". On s'est aligné sur les contrats d'interface attendus par disabled par exemple, càd n'importe quelle string considère que c'est "true". Voir https://stackblitz.com/edit/ember-cli-editor-output-pauj7r?file=app%2Ftemplates%2Fapplication.hbs

Un warning en environnement de dev a été ajouté en cas d'erreur potentielle. Ce warning ne s'exécutera pas dans un environnement de production (NODE_ENV=production) grâce à @ember/debug.

On a ajouté beaucoup de cas de tests pour s'assurer de ne pas casser les multiples cas d'usages dans le futur.

🌟 Remarques

À noter un comportement tricky de testing-library : une checkbox aria-disabled est "clickable" sans que ça ne throw, mais rien ne se passe (comme prévu).

🎅 Pour tester

S'assurer que les différents états de la Checkbox fonctionnent correctement, y compris avec VoiceOver.

S'assurer que les différents états du RadioButton fonctionnent correctement, y compris avec VoiceOver.

@yannbertrand yannbertrand added 👀 Tech Review Needed cross-team Toutes les équipes de dev labels May 13, 2024
@yannbertrand yannbertrand self-assigned this May 13, 2024
@pix-bot-github
Copy link

Une fois l'application déployée, elle sera accessible à cette adresse https://ui-pr638.review.pix.fr
Les variables d'environnement seront accessibles sur scalingo https://dashboard.scalingo.com/apps/osc-fr1/pix-ui-review-pr638/environment

@yannbertrand yannbertrand force-pushed the improve-checkbox-radio-disabled-docs branch from ef5f768 to 6f93ac2 Compare May 13, 2024 15:57
@yannbertrand yannbertrand changed the title [FEATURE] Mieux gérer les valeurs acceptées d'isDisabled des Checkbox [FEATURE] Mieux gérer les valeurs acceptées d'isDisabled des Checkbox/Radio May 13, 2024
addon/components/pix-radio-button.js Outdated Show resolved Hide resolved
addon/components/pix-radio-button.js Outdated Show resolved Hide resolved
@yannbertrand yannbertrand force-pushed the improve-checkbox-radio-disabled-docs branch from c6b2fb0 to bb436ac Compare May 14, 2024 07:22
Comment on lines 25 to 29
if (['false', 'null', 'undefined'].includes(this.args.isDisabled)) {
console.warn(
'PixCheckbox: @isDisabled attribute should be a boolean, a string was passed. Checkbox is considered disabled.',
);
}
Copy link
Contributor

@xav-car xav-car May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought :
Je suis pas fan d'ajouer ce genre de chose. car ça part en prod et c'est du code "inutil" pour l'usage final .
Ce genre de chose doit être valider lors de nos tests d'implem du composant. vérifier que le composant est bien disabled ou non dans nos cas d'usage. sinon on peut faire ça pour tout les @ qui prennent un boolean en paramètre ? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merci pour le partage 👍

On utilise déjà ce genre de chose dans PixMessage, ou des throw dans plusieurs components

En fait on aimerai bien s'éviter des futures erreurs (on a passé 1h dessus hier 😬). On peut être plus strict en throwant si besoin, mais même résultat pour l'usage interne ^^"

IMO ça reste un if sans trop d'impact et ça peut nous aider pas mal !

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne suis pas fan non plus des throw (j'ai tendance à les supprimer quand je les vois) qui partent aussi en prod. qui sont au final des cas qui n'arriveront jamais.

J'associe ça a du code pour nous aider a debugger (parcequ'on a mal lu la signature de PixUI, ou qu'on a mal écrite la doc du composant). Du coup à mon sens c'est du code "mort" puisqu'en production, on ne rentrera jamais dedans.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je crois avoir trouvé quelque chose pour répondre à nos deux problématiques !

Dans @ember/debug (officiel donc), il y a des méthodes de logs qui sont supprimées lors du build de production : https://api.emberjs.com/ember/5.8/classes/@ember%2Fdebug/methods/warn?anchor=warn.

Ça me semble être le meilleur de 2 mondes, non ? 😄

Copy link
Contributor

@xav-car xav-car May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

là je dis OUI (à tester )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ça fonctionne ! 1024pix/pix#8940 ✨ 🎉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image image

Copy link
Contributor

@xav-car xav-car left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mis à part mon opinion sur les bouts de code "dev mode" . le reste me paraît ok niveau tech

@xav-car
Copy link
Contributor

xav-car commented May 14, 2024

Func ok aussi

@yannbertrand yannbertrand force-pushed the improve-checkbox-radio-disabled-docs branch from bb436ac to 8a67c4e Compare May 15, 2024 12:50
return this.args.isDisabled || this.args.disabled;
warn(
'PixCheckbox: @isDisabled attribute should be a boolean, a string was passed. Checkbox is considered disabled.',
['false', 'null', 'undefined'].includes(this.args.isDisabled),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought : ![false,true].includes(this.args.isDisabled) serait plus clair. parce que l'on pourrait passer toto et le warn ne serait pas executé

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, j'ai aussi ajouté undefined car ça générait des warnings dans les cas de figure :

  • <PixCheckbox> (=> undefined)
  • <PixCheckbox @isDisabled={{undefined}}>

Pour être complet j'ai aussi ajouté null pour être plus permissif

  • <PixCheckbox @isDisabled={{null}}>

WDYT ?

@yannbertrand yannbertrand force-pushed the improve-checkbox-radio-disabled-docs branch 6 times, most recently from 17e5c76 to 3906f98 Compare May 15, 2024 13:56
@pix-service-auto-merge pix-service-auto-merge force-pushed the improve-checkbox-radio-disabled-docs branch from def54df to 58c39f1 Compare May 17, 2024 12:48
@pix-service-auto-merge pix-service-auto-merge merged commit 4cbb73a into dev May 17, 2024
5 of 6 checks passed
@pix-service-auto-merge pix-service-auto-merge deleted the improve-checkbox-radio-disabled-docs branch May 17, 2024 12:51
pix-service-auto-merge pushed a commit that referenced this pull request May 17, 2024
# [46.1.0](v46.0.3...v46.1.0) (2024-05-17)

### 🚀 Amélioration

- [#638](#638) Mieux gérer les valeurs acceptées d'`isDisabled` des Checkbox/Radio
@pix-service-auto-merge
Copy link
Contributor

🎉 This PR is included in version 46.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants