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

feat(input): add showPasswordToggle, hidePasswordIcon and showPasswordIcon properties #29141

Closed

Conversation

OS-giulianasilva
Copy link
Contributor

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?

  • Add three new properties:
    • 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?

  • Yes
  • No

Other information

Behavior on MD:
passwordToggleMD
Behavior on iOS:
passwordToggleios

@github-actions github-actions bot added package: core @ionic/core package package: angular @ionic/angular package package: vue @ionic/vue package labels Mar 12, 2024
@sean-perkins sean-perkins changed the base branch from main to feature-8.0 March 12, 2024 21:03
Copy link
Contributor

@sean-perkins sean-perkins left a 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 && (
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

core/src/components/input/input.tsx Outdated Show resolved Hide resolved
appearance: none;
}

:host(.in-item-color) .input-clear-icon {
:host(.in-item-color) .input-clear-icon,
:host(.in-item-color) .input-password-toggle {

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 {  
    } 
}

Copy link
Contributor Author

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.

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?

Copy link
Contributor

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.

Copy link
Contributor

@liamdebeasi liamdebeasi left a 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!

core/src/components/input/input.tsx Show resolved Hide resolved
core/src/components/input/input.tsx Outdated Show resolved Hide resolved
core/src/components/input/input.tsx Show resolved Hide resolved
core/src/components/input/input.tsx Outdated Show resolved Hide resolved
appearance: none;
}

:host(.in-item-color) .input-clear-icon {
:host(.in-item-color) .input-clear-icon,
:host(.in-item-color) .input-password-toggle {
Copy link
Contributor

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.

Comment on lines +226 to +227
:host(:not(.has-value)) .input-clear-icon {
visibility: hidden;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Comment on lines 26 to 38
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');
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment on lines 56 to 65
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');
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@liamdebeasi
Copy link
Contributor

Also you'll want to run npm run lint.fix from core and push your changes so the test-core-lint step passes.

liamdebeasi added a commit that referenced this pull request Mar 25, 2024
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]>
@thetaPC
Copy link
Contributor

thetaPC commented Apr 3, 2024

Thank you for contributing! I'm going to close this PR since the work was implemented through PR #29141.

@thetaPC thetaPC closed this Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: angular @ionic/angular package package: core @ionic/core package package: vue @ionic/vue package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants