Git Product home page Git Product logo

vaadin-text-field's Introduction

<vaadin-text-field>

⚠️ Starting from Vaadin 20, the source code and issues for this component are migrated to the vaadin/web-components monorepository. This repository contains the source code and releases of <vaadin-text-field> for the Vaadin versions 10 to 19.

<vaadin-text-field> is a themable Web Component providing input controls in forms, part of the Vaadin components.

Live Demo ↗ | API documentation ↗

npm version Published on webcomponents.org Published on Vaadin Directory Discord

<vaadin-text-field label="Username"></vaadin-text-field>
<vaadin-password-field label="Password"></vaadin-password-field>
<vaadin-text-area label="Description"></vaadin-text-area>
<vaadin-email-field label="Email"></vaadin-email-field>
<vaadin-number-field label="Price"></vaadin-number-field>
<vaadin-integer-field label="Count" has-controls></vaadin-integer-field>

Screenshot of vaadin-text-field

Installation

The Vaadin components are distributed as Bower and npm packages. Please note that the version range is the same, as the API has not changed. You should not mix Bower and npm versions in the same application, though.

Unlike the official Polymer Elements, the converted Polymer 3 compatible Vaadin components are only published on npm, not pushed to GitHub repositories.

Polymer 2 and HTML Imports Compatible Version

Install vaadin-text-field:

bower i vaadin/vaadin-text-field --save

Once installed, import the components you need in your application:

<link rel="import" href="bower_components/vaadin-text-field/vaadin-text-field.html">
<link rel="import" href="bower_components/vaadin-text-field/vaadin-text-area.html">
<link rel="import" href="bower_components/vaadin-text-field/vaadin-password-field.html">
<link rel="import" href="bower_components/vaadin-text-field/vaadin-email-field.html">
<link rel="import" href="bower_components/vaadin-text-field/vaadin-number-field.html">
<link rel="import" href="bower_components/vaadin-text-field/vaadin-integer-field.html">

Polymer 3 and ES Modules Compatible Version

Install vaadin-text-field:

npm i @vaadin/vaadin-text-field --save

Once installed, import the components you need in your application:

import '@vaadin/vaadin-text-field/vaadin-text-field.js';
import '@vaadin/vaadin-text-field/vaadin-text-area.js';
import '@vaadin/vaadin-text-field/vaadin-password-field.js';
import '@vaadin/vaadin-text-field/vaadin-email-field.js';
import '@vaadin/vaadin-text-field/vaadin-number-field.js';
import '@vaadin/vaadin-text-field/vaadin-integer-field.js';

Getting started

Vaadin components use the Lumo theme by default.

To use the Material theme, import the correspondent file from the theme/material folder.

Entry points

  • The components with the Lumo theme:

    theme/lumo/vaadin-text-field.html theme/lumo/vaadin-text-area.html theme/lumo/vaadin-password-field.html theme/lumo/vaadin-email-field.html theme/lumo/vaadin-number-field.html theme/lumo/vaadin-integer-field.html

  • The components with the Material theme:

    theme/material/vaadin-text-field.html theme/material/vaadin-text-area.html theme/material/vaadin-password-field.html theme/material/vaadin-email-field.html theme/material/vaadin-number-field.html theme/material/vaadin-integer-field.html

  • Aliases for theme/lumo/vaadin-text-field.html theme/lumo/vaadin-text-area.html theme/lumo/vaadin-password-field.html theme/lumo/vaadin-email-field.html theme/lumo/vaadin-number-field.html theme/lumo/vaadin-integer-field.html:

    vaadin-text-field.html vaadin-text-area.html vaadin-password-field.html vaadin-email-field.html vaadin-number-field vaadin-integer-field

Running demos and tests in a browser

  1. Fork the vaadin-text-field repository and clone it locally.

  2. Make sure you have npm and Bower installed.

  3. When in the vaadin-text-field directory, run npm install and then bower install to install dependencies.

  4. Run npm start, browser will automatically open the component API documentation.

  5. You can also open demo or in-browser tests by adding demo or test to the URL, for example:

Running tests from the command line

  1. When in the vaadin-text-field directory, run polymer test

Following the coding style

We are using ESLint for linting JavaScript code. You can check if your code is following our standards by running npm run lint, which will automatically lint all .js files as well as JavaScript snippets inside .html files.

Big Thanks

Cross-browser Testing Platform and Open Source <3 Provided by Sauce Labs.

Contributing

To contribute to the component, please read the guideline first.

License

Apache License 2.0

Vaadin collects development time usage statistics to improve this product. For details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.

vaadin-text-field's People

Contributors

abdonrd avatar alvarezguille avatar artur- avatar dependabot[bot] avatar diegocardoso avatar emarc avatar gatanaso avatar haprog avatar hdamr avatar jouni avatar klaudeta avatar limonte avatar manolo avatar marcushellberg avatar mukherjeesudebi avatar pekam avatar platosha avatar samiheikki avatar saulis avatar shadikhani avatar sissbruecker avatar sohrabtaee avatar someonetoignore avatar sosa-vaadin avatar tomivirkki avatar tulioag avatar vicsstar avatar vursen avatar web-padawan avatar yuriy-fix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vaadin-text-field's Issues

Safari 10.0 doesn’t support `minlength` validation

We should probably not expose the native minlength property, as Safari 10.0 doesn’t natively produce validation errors for that. We should instead encourage users to use pattern instead.

This has been fixed already in Safari Technology Preview.

Related: maxlength works in Safari 10.0 also, it prevents the user from inputting more characters.

Also, it seems that minlength and maxlength are only evaluated for user input, and they don’t affect the validation unless the user has touched modified the input. The pattern property, on the other hand, is validated already when the element is loaded/rendered.

Built-in “clear” button

As an opt-in feature (or opt-out, can be discussed), provide a built-in suffix element which, when clicked/tapped, sets the value of the field to an empty string.

The element should be an “X” icon and be shown before any other suffix elements (closest to the value).

Question: When the field is marked as required, should the clear button always be hidden?

Accessibility support

For reference: https://www.w3.org/TR/wai-aria-1.1/#textbox

Proposal: should support announcing label by the screenreader, also should announce states like disabled, readonly, invalid and required (and error message).

Also the value should be announced :doh:. And should announce that the user is in a textbox.

All the announcements should work out of the box without requiring the users to add any aria attributes themselves. aria-label can of course be used to override the default announcement.

Should be tested on VoiceOver (OSX + iOS), ChromeVox, JAWS and NVDA on Windows 10, Android TalkBack

Infinite loop in Firefox

Script is working for 20 seconds and then "Unresponsive script" alert is shown in Firefox/Linux:

recorded

Add visual testing

  • Add .gemini.yml
  • Add Travis test step
  • Add npm deps
  • Add reference pics for different states (focused, hovered, invalid, etc.) to repository
  • Add configuration files also to skeleton project

Tabbing issues in FF

If you use tab to move focus from a <vaadin-text-field> to another, the first time it works as expected. Shift+tab back to the first field and hit tab again to focus the second field again and the focus gets lost.

Occurs on FF

Error message

Specs by @jouni

It should be possible to provide an error message for the text-field, which gets announced by the screen reader, for example in the case of a validation error.

The error message should only be displayed when the text field is invalid.

API proposal:

<vaadin-text-field error-message="This field is required" label="Name" required></vaadin-text-field>

Implementation details

Expose the error message as a new themable part, e.g.

# shadow root
  ...
  <div class="error" part="error-message">[[errorMessage]]</div>
  ...

The error message should be displayed under the field by default. No extra styling is needed (colors or anything else).

Add label

  • Label position should be definable by CSS
    • separate positions can be defined for states: input empty/non-empty, focused
  • Default position for the label is on top of the field (like always-float-label on <paper-input>
  • Consider support for form-layout

API docs: missing state attributes

Attributes such as focused, focus-ring, disabled, invalid are available on the host element for styling, but not listed in the API docs as of now.

API documentation should list all of the attributes available for styling.

Rename to `vaadin-text-field`

As the native <input> element has the type attribute, which can make the element behave completely differently from a text input (such as "checkbox" and "range"), and since we have TextField and TextArea components in the Vaadin Framework currently, I think it would be better if we changed the name of this element. Then, it is more natural to create a <vaadin-text-area> element for multi-line text.

This would also make comparisons to paper-input less obvious.

Remove autofocus demo

Currently, after opening the page, the autofocus example makes it scroll away from the top. This obscures first few examples on the page.

(This is the DX tests finding)

Simplify internal structure

  • Drop the label-and-input-container so that the content-wrapper ends up with only prefix, input and suffix.
  • Replace label-placeholder with the actual label
  • Consider dropping the outer container wrapper

Not working in Edge

The demo pages are not rendered.

Console has an error:

Unable to get property 'cssText' of undefined or null reference: webcomponents-lite.js (5,42707)

Prevent invalid input

Use cases:

  • applies only to sync validation
  • opt-in feature to prevent user from typing values that would be invalid
  • should of course work with custom validators also
  • iron-input has a corresponding property called prevent-invalid-input

Theming Example

  • Main purpose is to document using the all "parts" for theming.
  • List all the parts in the API docs (vs. the old CSS mixins)
  • Let's use Bootstrap as inspiration for visual end result
  • Add also visual regression testing to make sure each "part" works

Set a default height for part=input-field

Adding/removing icons to prefix/suffix slots makes the element layout change.

That is an issue when adding mobile friendly clear/toggle buttons in other elements like vaadin-combo-box. Otherwise setting a height in other elements needs to define a theme block and repeat all theme-default properties.

Here a screenshot with the problem and possible solution

http://g.recordit.co/nDrZJnpxqv.gif

Prefix and Suffix

Use Cases to cover:

  • allow adding icons/buttons inside the focusable area (think of combo-box)
  • consider disabling "floating label" when prefix is defined

Custom validators

Definition of Done: add examples how to extend the VaadinTextFieldElement to provide:

  • synchronous custom validation
  • asynchronous custom validation

Remove CSS mixins

After #45 is completed, remove mixins and fix Material design demo using the new style module injection.

  • Move the material design theming demo to vaadin-themes, just add a page with a material design themed vaadin-text-field
  • Add visual regression tests
  • Make sure nightly builds are run to prevent visual regressions

Add visualization when invalid input is prevented

Currently, when prevent-invalid-input in enabled and user tries, for example, to type letters in a numbers-only field, nothing happens.

UX is poor, we should somehow indicate that input was prevented. Without the indication, the user thinks that his keyboard is broken or there's some virus in his lovely Android phone.

Indication by default could be red border (shadow-box) blink for a short moment right after typing.

(This is the DX tests finding)

Add theming support and theme

Definition of Done:

  • Add the possibility to theme the input (MVP should support material design look without the floating label thing)
  • Design a "default" look for input, styles included inside the element
  • By default it should look like a native input

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.