-
-
Notifications
You must be signed in to change notification settings - Fork 364
new TogglePassword component #1000
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
Conversation
Icon customization could be useful too |
Hi, I'm wondering:
|
Thanks for your feedbacks @norkunas and @jmsche ! 👍🏼 About the {{ form_row(form.password, { 'hidden_label': 'password_hide'|trans, 'visible_label': 'password_show'|trans }) }} will work with provided theme. But i'll look into |
I think Autocomplete uses an extension as well :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, this looks pretty sweet 😎. I agree with the suggestions (including the form type extension) and about making a few things more overridable + the translations stuff. Once we've got that, I'll try this out for real. But I like how this aims to just "drop in and work" for most cases but then can be configured by overriding the CSS.
Also, congrats on PR #1000! 🥳
We can help with that: https://stimulus-password-visibility.stimulus-components.com/ Their template is: <div data-controller="password-visibility">
<input type="password" data-password-visibility-target="input" spellcheck="false" />
<button type="button" data-action="password-visibility#toggle">
<span data-password-visibility-target="icon">Eye</span>
<span data-password-visibility-target="icon" class="hidden">Eye Slash</span>
</button>
</div> |
Thanks for the suggestion @seb-jean 👍🏼 but i must admit i'm not fully on board with their template approach on this one. I'd rather instantiate the stimulus controller on the password input (which is the main "actor" in this case), then create the action button and update its content without having all options loaded in the browser by default all the time. To me, the logic belongs to the stimulus controller scope, not the DOM |
Based on your reviews and suggestions (thanks again for those 🙏🏼 ) :
I'm still working on the translation support for labels 👍🏼 |
Thanks again @jmsche for your review and suggestions 👍🏼
|
Some quick notes as I'm on a phone, I'll review this more deeply tomorrow:
Thanks for all your work :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some minor changes.
Still missing a note in the docs about translating labels. And what about the translation domain option for labels? Would you add it, or make the developer consider using TranslatableMessage instead?
Absolutely @jmsche ! Commiting your suggestion resolved the conversation and i forgot about it but i agree, i'll add a translation domain option for labels 👍🏼 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems great!
Thanks for all the changes, and sorry for all the comments 😄
No worries at all, it was super relevant and interesting ! Thank you for your time and reactivity ! 👍🏼 |
@weaverryan i've updated PR description to include all changes added with reviews and suggestions made, if you want to take a look and try it out, i think it looks quite clean and ready now 😄 👍🏼 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really good!
line-height: 1.25rem; | ||
position: absolute; | ||
right: 0.5rem; | ||
top: -1.25rem; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to be the trickiest part of this PR. Can we make some CSS that works in "most" cases. I was testing locally on https://ux.symfony.com/live-component/demos/auto-validating-form
I see the form theme template, which contains the toggle-password-container
class, which is the key to making this all work "out of the box". I also see that you prepended the config to add this form theme automatically - smart! Unfortunately... because ux.symfony.com already uses a form theme, by prepending the config, the custom bootstrap_5_layout.html.twig
from that project shows up last in the list, and so its form theme wins (and the one from this bundle isn't used). I also think that there should probably be a way to "opt out" of the form theme - you may want to use your normal password_widget
rendering (without the new div) and then use your own CSS to place things correctly.
I'm not convinced I have the correct solution for this. But my idea is:
A) Remove the prepend and instead document the user adding the form theme manually. It kinda sucks to do this... but then the user can opt out of it.
B) Document that, instead of the form theme, you can also style manually.
Another idea, might be to:
- In
TogglePasswordTypeExtension
, add a newtoggle_form_theme
option, which defaults totrue
. - In
TogglePasswordTypeExtension
, if that's true, add a new item to theblock_prefixes
variable - like thisarray_splice($view['autocomplete']->vars['block_prefixes'], -1, 0, 'ux_entity_autocomplete_inner'); ux_password_toggle
. - Change the form theme template to override just that block - e.g.
ux_password_toggle_widget
.
The idea would be that, if toggle_form_theme
is true, then it will use your form theme. If false, it will skip and use the normal. Additionally, in your form theme (form_theme.html.twig
), I believe you could then:
-{ block('form_widget') }}
+{ block('password_widget') }}
So in the event the user is overriding the password_widget
in a custom form theme, we will still use that.
Also, we should document how this all works a bit - basically communicating:
A) There is a custom form theme that's activated, which wraps your widget in a <div class="toggle-password-container">
.
B) You can turn this off with the toggle_form_theme
option, but then you're on your own to style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch ! Indeed, that's tricky but absolutely relevant !!
I'd go for your second suggestion, adding a toggle_form_theme boolean option, which would define a block prefix 👍🏼
Let's go for that 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done !
I went for use_toggle_form_theme
option, with true
as default value so it can add a custom block prefix : ux_toggle_password
(to keep consistency with the names used everywhere else in the package) and i add documentation about the behaviour to expect.
I tried to be as clear as possible on this one while while remaining as concise as possible. I hope it's clear enough, otherwise i'll try another way 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small comment - but I'm going to merge. This is very high-quality work - it was a pleasure to review and test. Thank you! Once we have a sub-tree split, would you mind creating a PR to ux.symfony.com to add a page for it? Also, once released, we should add the option to https://symfony.com/doc/current/reference/forms/types/password.html with a link over to the bundle
"types": "dist/controller.d.ts", | ||
"config": { | ||
"css_source": "src/style.css" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this config
key. I had never noticed that we had this on a few other, old packages. I believe it was added by accident there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, i'll remove it 👍🏼
I thought it was needed for the css file provided with the bundle !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably was in a very early WIP version of UX + Flex - that's my best guess :)
7874579
to
b1bf8f0
Compare
Thanks a lot to you too for your time and review @weaverryan 👍🏼 |
Thank you! The sub-tree split and packagist package now exist - https://github.com/symfony/ux-toggle-password - so you should be able to create the ux.symfony.com page (we don't need a release for this - we bring in the latest, dev versions of packages inside the ux.symfony.com directory anyway). |
Awesome 👍🏼 i'll create the ux.symfony.com page in a couple of hours and submit a PR for it once ready 😄 |
@feymo ux.symfony.com page is live! The release is out and the docs are up. Would you mind creating a PR to https://github.com/symfony/symfony-docs to: A) Document the new option (with a link to the component) on https://symfony.com/doc/current/reference/forms/types/password.html Thanks! |
@weaverryan Thanks ! i'll work on these as soon as possible 👍🏼 |
Hello to the Symfony UX community !
This PR propose a new Symfony UX Component.
The
TogglePassword
component allows users to switch visibility on password inputs through a dedicated button.Default style is provided and english language is used for labels but everything is customizable to fit projects requirements.
Here are screenshots previews for the default rendering :


Thanks you all in advance for your feedbacks and comments on the relevance of a component like this within Symfony UX ! 😄
Edit: The TogglePassword component propose :
FormExtension
transforming anyPasswordType
field into a Toggle Password by adding thetoggle
option ;TranslatableMessage
object or translation key string with domain) and the option to disable translation ;