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

Add <vaadin-text-field-container> #1411

Closed
platosha opened this issue Apr 13, 2017 · 7 comments
Closed

Add <vaadin-text-field-container> #1411

platosha opened this issue Apr 13, 2017 · 7 comments
Labels
enhancement New feature or request vaadin-text-field

Comments

@platosha
Copy link
Contributor

Create <vaadin-text-field-container> element, which is a themable container for an <input> element provided by users in the light DOM.

Resolves vaadin/vaadin-text-field#38 and vaadin/vaadin-text-field#48.

Motivation

Exposing <input> for direct access gives accessibility benefits. <label> element bindings and attributes without any hacks/manual support from the <vaadin-text-field>.

Currently with <vaadin-text-field>, using <label> is problematic: it does not announce <label> as an accessible name when native Shadow DOM is used, because <label> is in the parent tree, while the focused <input> is in the shadow tree of <vaadin-text-field>:

<label>
  Foo
  <vaadin-text-field>
    ::shadow-root
    <input>
  </vaadin-text-field>
</label>

With <vaadin-text-field-container>, users can assign accessible labels with <label> element (#useThePlatform 👍):

<!-- <label> is in the same tree with <input>, works fine -->
<label>
  Foo
  <vaadin-text-field-container>
    <input>
  </vaadin-text-field-container>
</label>

<!-- using <label for="">, also works fine -->
<label for="myInput">Foo</label>
<vaadin-text-field-container>
  <input id="myInput">
</vaadin-text-field-container>

<!-- works for <vaadin-form-item> as well out-of-the-box -->
<vaadin-form-item>
  <label slot="label" for="fooInput">Foo</label>
  <vaadin-text-field-container>
    <input id="fooInput">
  </vaadin-text-field-container>
</vaadin-form-item>

Users can assign aria-label and other ARIA attributes on the input directly:

<!-- using aria-label on the input, works fine as well -->
<vaadin-text-field-container>
  <input aria-label="Foo">
</vaadin-text-field-container>

Users can use a custom input type and other native <input> attributes:

<vaadin-text-field-container><input type="password"></vaadin-text-field-container>
@jouni
Copy link
Member

jouni commented Apr 13, 2017

Style leaks are unavoidable with this approach, of course, so it’s no silver bullet it that sense. It is fine when you can wrap it inside another shadow tree (like we encapsulate paper input in vaadin-combo-box/date-picker), but using it inside the light dom of vaadin-form-layout seems more prone to unwanted style leaks.

@platosha
Copy link
Contributor Author

@jouni style leaks are workaroundable. Naturally, themes need to define all appearance properties for <input>, as they need to override UA default styles anyway. If these theme styles are specific enough, they can override global styles as well.

For example, if a theme will use !important for slotted input styles, then non-important global styles won’t override it. Another option for users is to wrap the entire form contents (with vaadin-form-layout) in a shadow tree.

We can’t protect against !important in non-scoped global styles, but either shadow trees don’t protect with ShadyDOM polyfill.

Here are some quick JSbin demos.

@paales
Copy link

paales commented Apr 12, 2018

Reasons for the container:

  • You can't use a native <form>, working with iron-form is a b*tch (pardon my language)
  • Password managers break (lastpass, etc.)
  • Autocomplete doesn't work: Address / credit card fields

@web-padawan
Copy link
Member

web-padawan commented Apr 12, 2018

@paales please keep in mind that password managers and autocomplete are expected to break anyways, when using any Web Component with shadow root for the whole app / single view inside of it.

What problems do you have regarding iron-form support for vaadin-text-field?

@jouni
Copy link
Member

jouni commented Apr 12, 2018

Slightly related (a more generic field wrapper element): vaadin/vaadin-core#150

@paales
Copy link

paales commented Apr 12, 2018

please keep in mind that password managers and autocomplete are expected to break

Not when you have the form in the same scope as the input field. It is not the issue that the autocomplete can't penetrate the shadow dom boundary, just that the values are set from the 'level' of the form and thus cant find the inputs. Autocomplete matters.

@vaadin-bot vaadin-bot transferred this issue from vaadin/vaadin-text-field May 19, 2021
@vaadin-bot vaadin-bot added enhancement New feature or request vaadin-text-field labels May 19, 2021
@web-padawan
Copy link
Member

Closing in favor of #2185 where this will be partially handled. See also #84 for an epic with all related tickets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request vaadin-text-field
Projects
None yet
Development

No branches or pull requests

5 participants