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

DatePicker: add setAutoSelect API #1110

Open
vaadin-miki opened this issue Apr 20, 2020 · 5 comments
Open

DatePicker: add setAutoSelect API #1110

vaadin-miki opened this issue Apr 20, 2020 · 5 comments
Labels
enhancement New feature or request vaadin-date-picker

Comments

@vaadin-miki
Copy link
Contributor

When focusing the date picker, it should be possible to automatically select the text that is in the component, similarly to what textField.setAutoselect(true) does.

A workaround exists by adding a focus listener that executes JS that does this.$.input.inputElement.select() - but this relies on the internals of the component.

@vaadin-bot vaadin-bot transferred this issue from vaadin/vaadin-date-picker-flow Oct 6, 2020
@vaadin-bot vaadin-bot transferred this issue from vaadin/vaadin-date-picker May 19, 2021
@vaadin-bot vaadin-bot transferred this issue from vaadin/web-components May 21, 2021
@vaadin-bot vaadin-bot added enhancement New feature or request vaadin-date-picker labels May 21, 2021
@hfazai
Copy link

hfazai commented Oct 26, 2021

+1

@web-padawan
Copy link
Member

This is actually implemented in Vaadin 22 on the web component side vaadin/web-components#2750

The only remaining change is to copy setAutoSelect API and unit tests from TextField to DatePicker.

@web-padawan web-padawan changed the title Allow autoselect on focus DatePicker: add setAutoSelect API Oct 26, 2021
@hons82
Copy link

hons82 commented Nov 4, 2021

This should be added for TimePicker and DateTimePicker as well...
If I may express a wish 👍🏼

@kkleinwi
Copy link

Adding my vote for this enhancement.

@samie
Copy link
Member

samie commented Mar 14, 2023

Here is a static helper for TextField and ComboBox, DatePicker TimePicker and DateTimePicker:

public static void setAutoselect(com.vaadin.flow.component.Component... components) {
        for (com.vaadin.flow.component.Component c: components) {
            if (c instanceof TextField) {
                ((TextField)c).setAutoselect(true);
            } else if (c instanceof ComboBox) {
                c.getElement().executeJavaScript("this.inputElement.autoselect=true;");
            } else if (c instanceof DatePicker) {
                c.getElement().executeJavaScript("this._inputElement.autoselect=true;");
            } else if (c instanceof DateTimePicker) {
                c.getElement().executeJavaScript("this.__datePicker._inputElement.autoselect=true;this.__timePicker.__inputElement.autoselect=true;");
            } else if ( c instanceof TimePicker) {
                c.getElement().executeJs("this.__inputElement.autoselect = true;");
            }
        }
    }

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-date-picker
Projects
None yet
Development

No branches or pull requests

7 participants