Skip to content

add password and email textbox types#2653

Merged
pngwn merged 8 commits into
mainfrom
text-type
Nov 15, 2022
Merged

add password and email textbox types#2653
pngwn merged 8 commits into
mainfrom
text-type

Conversation

@pngwn
Copy link
Copy Markdown
Member

@pngwn pngwn commented Nov 15, 2022

Description

Adds a new kwarg for Textbox, type. Defaults to 'text' (current behaviour) but can optionally be set to 'password' or 'email'. 'email' should autocomplete emails and could support patterns in the future. 'password' blanks out the characters. Both 'email' and 'password' force the textbox to have a maxlines value of of 1 (because you can't have multiline password or email input types).

To test: add type='password' to any Textbox demo.

Closes half of #2029 but i don't actually want to close that issue for obvious reasons.

Please include:

  • relevant motivation
  • a summary of the change
  • which issue is fixed.
  • any additional dependencies that are required for this change.

Closes: # (issue)

Checklist:

  • I have performed a self-review of my own code
  • I have added a short summary of my change to the CHANGELOG.md
  • My code follows the style guidelines of this project
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

A note about the CHANGELOG

Hello 👋 and thank you for contributing to Gradio!

All pull requests must update the change log located in CHANGELOG.md, unless the pull request is labeled with the "no-changelog-update" label.

Please add a brief summary of the change to the Upcoming Release > Full Changelog section of the CHANGELOG.md file and include
a link to the PR (formatted in markdown) and a link to your github profile (if you like). For example, "* Added a cool new feature by [@myusername](link-to-your-github-profile) in [PR 11111](https://github.com/gradio-app/gradio/pull/11111)".

If you would like to elaborate on your change further, feel free to include a longer explanation in the other sections.
If you would like an image/gif/video showcasing your feature, it may be best to edit the CHANGELOG file using the
GitHub web UI since that lets you upload files directly via drag-and-drop.

@pngwn pngwn requested a review from freddyaboulton November 15, 2022 19:06
@github-actions
Copy link
Copy Markdown
Contributor

All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-2653-all-demos

@pngwn
Copy link
Copy Markdown
Member Author

pngwn commented Nov 15, 2022

why are you being like this

Copy link
Copy Markdown
Collaborator

@freddyaboulton freddyaboulton 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 to me @pngwn !

I think it would be worthwhile to raise an exception on the backend during the textbox init if type is not "text", "email" or "password" otherwise the front-end will break.

Might also be good to add a unit test about max_lines being set to 1 for password and email types.

The auto complete for email doesn't seem to work for me (I hit tab and all it does it take me to another component). Not a dealbreaker for me but wanted to bring it up to your attention.

@pngwn
Copy link
Copy Markdown
Member Author

pngwn commented Nov 15, 2022

@freddyaboulton The autocomplete is just the browser default, so in theory it should work however your browser's autocomplete/ autofill works but mine seems to be pretty inconsistent. Tabbing is still expected to change focus.

I'll do the other things.

@pngwn
Copy link
Copy Markdown
Member Author

pngwn commented Nov 15, 2022

@freddyaboulton
I added some tests for max_lines (with all types) and to check the error is correctly raised when a faulty type is passed.

lmk if they're okay, i have no idea what i'm doing.

Comment thread test/test_components.py
assert component.get_config().get("value") == "abc"
assert component.get_config().get("lines") == 4

def test_faulty_type(self):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks pretty good to me @pngwn !

Copy link
Copy Markdown
Collaborator

@freddyaboulton freddyaboulton Nov 15, 2022

Choose a reason for hiding this comment

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

I think you just need to modify the default value of type in gr.inputs.Textbox to be text

@pngwn
Copy link
Copy Markdown
Member Author

pngwn commented Nov 15, 2022

ok we good

@pngwn
Copy link
Copy Markdown
Member Author

pngwn commented Nov 15, 2022

Thanks for the review @freddyaboulton !

@pngwn pngwn merged commit 4b57984 into main Nov 15, 2022
@pngwn pngwn deleted the text-type branch November 15, 2022 21:23
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.

2 participants