Skip to content

(CDPE-3578) Add show/hide capabilities for <Input> #282

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

Merged
merged 5 commits into from
Aug 21, 2020

Conversation

eputnam
Copy link
Contributor

@eputnam eputnam commented Aug 13, 2020

(CDPE-3578) Add api for show/hide to
Currently, the trailing and leading icons on the Input component are only icons. This commit makes changes to the Input component api to allow a callback to be passed to the icon to facilitate a password show/hide for example. This includes a boolean to turn the icon into a button and then a prop so that the consumer can pass an onClick to the button.

(CDPE-3578) Fix styles, add interactive example & CHANGELOG
I was having trouble with CSS inheritence and honestly its probably not right still, but I was able to make the leading icon sit all the way to the left finally. This change also adds to the Input.md and adds a CHANGELOG entry for these changes as per CONTRIBUTING.md

ezgif com-video-to-gif

@eputnam eputnam requested a review from a team as a code owner August 13, 2020 19:34
@eputnam eputnam marked this pull request as draft August 13, 2020 19:39
@eputnam eputnam marked this pull request as ready for review August 14, 2020 14:52
@eputnam
Copy link
Contributor Author

eputnam commented Aug 14, 2020

definitely open to thoughts on the api here. these two props (iconButton and onClickIconButton) make it probably as flexible as possible but the thought also occurred to me that we maybe don't want that. what other functions do we image the button having? would it make sense to just have a showHide prop instead?

@woodburndesigns
Copy link
Contributor

Hey @eputnam I definitely see your concern with the API. In this particular case a consumer could potentially add a leading AND trailing button. Currently, if the consumer also provided the onClickIconButton the function would be fired on both elements potentially leading to confusion. Do you know if there have been any cases where folks wanted both leading and trailing icons?

@Sigler
Copy link
Contributor

Sigler commented Aug 14, 2020

Hey Eric. Been reviewing this with Geoff and thinking about other use cases without making this too complex.

A few thoughts:

  • Let's keep the icon that describes the input separate from the icon used in the button. eg. A key might be used on the left, and the eye might be used for the button.
  • It is not intended that the icon on the left, or lead, be clickable. That affords us some wiggle room if we can agree that the trailing side be reserved for actions.
  • Other use cases for a more general button would be an "x" to clear all, or a "+" for adding something.
  • A nice to have would be flexibility to allow for a text string on the action - such as a "+ Add item". We don't have an immediate use case, thus why I think its nice-to-have only.

@Sigler
Copy link
Contributor

Sigler commented Aug 14, 2020

Another thought.

If the trailing side is reserved for actions then we should plan to deprecate the trailing icon prop.
Alternatively we need to account for the position of the trailing icon and the button to be present simultaneously. While that is incredibly flexible it comes at the expense of quite a bit more complexity.

@eputnam
Copy link
Contributor Author

eputnam commented Aug 17, 2020

@Sigler , @woodburndesigns , thanks for the reviews!

So how bout this: (cc: @vine77 )

  1. Revert changes to the leading icon so it's back to just being an icon
  2. Revert changes to trailing icon and instead add
    trailingButtonIcon: name of the icon for the button. just like "icon" or "trailingIcon" a value here determines whether the component is present.
    trailingButtonText: optional text for the button, we could treat this like the icon prop too. if only text is provided, we would just have a text-only button.
    onClickTrailingButton: callback for the button
  3. When the trailing button is present, put the icon to the left of the button (?) using the spacing already built into the components.
  4. Add deprecation notice of some kind (open to direction here) to the trailingIcon prop.

@woodburndesigns
Copy link
Contributor

Sounds good to me! Lets go for it for now @eputnam

@Sigler
Copy link
Contributor

Sigler commented Aug 18, 2020

Looks good. On your 4th point, we can add an info section about trailingIcons being deprecated in 2.0. We should also emphasize it in the notes and communicate it in the slack channel.

I'm not sure how to best implement it, but it would be nice to be able to pull up a list of everything to be deprecated in 2.0 that we can communicate when we get closer to launch.

value={state['input-ex13-value']}
trailingIcon="eye"
placeholder="We will eventually use this for a masked input"
iconButton
placeholder="Use the trailing icon for showing/hiding passwords"
Copy link

Choose a reason for hiding this comment

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

Can the button be provided with an aria-label attribute to provide an accessible name for the button? Placeholder is not reliably announced by assistive technology.

@eputnam eputnam force-pushed the CDPE-3578/show-hide-for-input-component branch from 7e56cc2 to f907c01 Compare August 19, 2020 15:18
@eputnam
Copy link
Contributor Author

eputnam commented Aug 19, 2020

with trailingIcon and trailingButtonIcon
Screen Shot 2020-08-19 at 9 50 50 AM

with trailingButtonIcon
Screen Shot 2020-08-19 at 9 50 56 AM

with trailingButtonIcon and trailingButtonText
Screen Shot 2020-08-19 at 9 54 49 AM

The only snag in this is the icon and button are absolutely positioned, so if you want to have an icon and a button with text (length/width unknown), you're gonna have a bad time. Making that work will mean changing more things and it seems like that's an edge case. If that needs to be an option, let me know.

Copy link
Contributor

@woodburndesigns woodburndesigns left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for the updates.

Currently, the trailing and leading icons on the Input component are only icons. This commit makes changes to the Input component api to allow a callback to be passed to the icon to facilitate a password show/hide for example. This includes a boolean to turn the icon into a button and then a prop so that the consumer can pass an onClick to the button.
I was having trouble with CSS inheritence and honestly its probably not right still, but I was able to make the leading icon sit all the way to the left finally. This change also adds to the Input.md and adds a CHANGELOG entry for these changes as per CONTRIBUTING.md
This adds a basic basic test to make sure the icon is wrapped in a button and the button receives a click with the correct props
The linter doesn't like the 'none' value for getting rid of the border on the leading/trailing button, so i tried hidden instead and it was fine. Yey. This is probably one of many css conventions I'm not familiar with.
This commit changes what we're doing a little bit with the button functionality in the Input component. We decided to leave the leading icon out of it all together and just add a trailing button. Now, to add a trailing button, users can either define the trailingButtonIcon prop and/or the trailingButtonText with the onClickTrailingButton prop to get the button going. I also added a trailingButtonProps prop so users can pass things like aria-label to the button. Also, trailingIcon is deprecated.
@vine77 vine77 force-pushed the CDPE-3578/show-hide-for-input-component branch from f907c01 to fd1f670 Compare August 21, 2020 15:05
@vine77
Copy link
Contributor

vine77 commented Aug 21, 2020

I'm merging this, but wanted to include a screenshot here of the issue with absolute positioning when using trailingButtonText:

Screen Shot 2020-08-21 at 8 11 17 AM

@vine77 vine77 merged commit 5a2c5ab into development Aug 21, 2020
@vine77 vine77 deleted the CDPE-3578/show-hide-for-input-component branch August 21, 2020 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants