-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
feat(input): add showPasswordToggle, hidePasswordIcon and showPasswordIcon properties #29141
feat(input): add showPasswordToggle, hidePasswordIcon and showPasswordIcon properties #29141
Conversation
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.
Couple of initial questions, great work so far!
I've updated the targeted branch to feature-8.0
since we will not be releasing any additional minor release changes other than what we've already committed and v8 is close 🎉
You will need to either merge feature-8.0
into your branch and resolve the merge conflicts or rebase. api.txt
, components.d.ts
and the proxies.ts
are auto-generated from npm run build
, so you can take whatever diff and then re-generate the results.
Once we are up to date with feature-8.0
I can help get screenshots generated and merged into your fork. The team is actively working to remove this restraint in the near future so you can update screenshots locally.
@@ -836,6 +857,30 @@ export class Input implements ComponentInterface { | |||
<ion-icon aria-hidden="true" icon={mode === 'ios' ? closeCircle : closeSharp}></ion-icon> | |||
</button> | |||
)} | |||
{this.showPasswordToggle && !readonly && !disabled && ( |
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.
The design document described rendering this content as the default content of the end
slot.
Did we experience an issue or additional consideration to not render it as the default slot content?
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.
Actually, this is something that I overlooked in the design document. But now testing it as the default content of the end slot, I noticed that the password toggle button will be hidden when the end slot is used.
I think this would impact some use-cases. For example, if the developer wants to use the password toggle and also add a green checkmark icon to the end slot to represent the validation of the strength of the password, it will not be possible to achieve.
Please let me know your thoughts on it.
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.
Let's talk about this internally.
appearance: none; | ||
} | ||
|
||
:host(.in-item-color) .input-clear-icon { | ||
:host(.in-item-color) .input-clear-icon, | ||
:host(.in-item-color) .input-password-toggle { |
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.
let's break this into
:host(.in-item-color){
.input-clear-icon,
.input-password-toggle {
}
}
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.
I would like to keep it as it is, because it is more readable and also matches the current CSS structure of the code.
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.
@sean-perkins what do you think about this topic?
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.
Most CSS we've written in Ionic avoids nested to keep the code readable. However, I think either would be fine -- really comes down to a matter of preference.
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.
Great work so far!
appearance: none; | ||
} | ||
|
||
:host(.in-item-color) .input-clear-icon { | ||
:host(.in-item-color) .input-clear-icon, | ||
:host(.in-item-color) .input-password-toggle { |
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.
Most CSS we've written in Ionic avoids nested to keep the code readable. However, I think either would be fine -- really comes down to a matter of preference.
:host(:not(.has-value)) .input-clear-icon { | ||
visibility: hidden; |
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.
Why was this change made?
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.
Because otherwise, the clear icon would not disappear when the input is erased.
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.
The clear icon currently disappears when the input is erased on the latest stable version of Ionic: https://ionicframework.com/docs/api/input#clear-options
If that's not the case in this branch, then there may be other code impacting that.
const input = page.locator('ion-input'); | ||
const nativeInput = page.locator('.native-input'); | ||
const toggle = input.locator('.input-password-toggle'); | ||
|
||
await toggle.click(); | ||
await page.waitForChanges(); | ||
|
||
await expect(nativeInput).toHaveAttribute('type', 'text'); | ||
|
||
await toggle.click(); | ||
await page.waitForChanges(); | ||
|
||
await expect(nativeInput).toHaveAttribute('type', 'password'); |
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 could be a spec test. We don't necessarily benefit from having cross-browser testing here.
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.
Makes sense! I will take care of this tomorrow.
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.
Done!
const input = page.locator('ion-input'); | ||
const toggle = input.locator('.input-password-toggle'); | ||
const icon = toggle.locator('ion-icon'); | ||
|
||
await expect(icon).toHaveJSProperty('icon', 'bus'); | ||
|
||
await toggle.click(); | ||
await page.waitForChanges(); | ||
|
||
await expect(icon).toHaveJSProperty('icon', 'cafe'); |
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.
Same as previous comment, we don't really value from having cross-browser testing here so this could be a spec test.
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.
Same as above.
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.
Done!
Also you'll want to run |
Issue number: Internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> When given a password input it is hard to know what users are typing as the contents of the input are obscured. As a result, it is a common pattern to have a button that lets users temporarily toggle the visibility of the password so they can correct any mistakes. Ionic currently has the infrastructure for developers to implement this on their own, but this use case is so common that the team thinks it is worth having this functionality built-in to Ionic. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Introduces the `ion-input-password-toggle` component. This component is a button that toggles the visibility of the text in the input it is slotted into. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#footer for more information. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. -->⚠️ Give co-author credit to #29141 on merge. Docs PR: ionic-team/ionic-docs#3541 Note: We did not do the approach listed in the other PR due to #29141 (comment). --------- Co-authored-by: OS-giulianasilva <[email protected]>
Thank you for contributing! I'm going to close this PR since the work was implemented through PR #29141. |
Issue number: Internal
What is the current behavior?
The ion-input does not provide an ability to toggle password visibility on input
What is the new behavior?
showPasswordToggle
to enable the passwordToggle button in the input that when clicked toggles the input type between"text"
and"password"
, allowing the user to view or hide the input value.showPasswordIcon
to set the icon to be used to represent showing a password.hidePasswordIcon
to set the icon to be used to represent hiding a password.Does this introduce a breaking change?
Other information
Behavior on MD:
Behavior on iOS: