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

Create HasPlaceholder interface #4068

Closed
mvysny opened this issue May 4, 2018 · 6 comments · Fixed by #18081
Closed

Create HasPlaceholder interface #4068

mvysny opened this issue May 4, 2018 · 6 comments · Fixed by #18081

Comments

@mvysny
Copy link
Member

mvysny commented May 4, 2018

Similar to HasEnabled in #3816

@pleku
Copy link
Contributor

pleku commented Mar 8, 2019

@mvysny what for would you want to use this mixin interface for ?

Even though it is very generic bit of API and works the same way for all the components, meaning that it could be thus in a mixin interface, I don't see it would add that much value.

@pleku pleku added this to the Not Planned milestone Mar 8, 2019
@mvysny
Copy link
Member Author

mvysny commented Mar 8, 2019

In Karibu Testing I'm allowing the user to filter the components also based on the placeholder. However, there is no unified interface that can return the placeholder for a component, and therefore I had to write the following function:

val Component.placeholder: String?
    get() = when (this) {
        is TextField -> placeholder
        is TextArea -> placeholder
        is PasswordField -> placeholder
        is ComboBox<*> -> this.placeholder
        is DatePicker -> placeholder
        is Input -> placeholder.orElse(null)
        else -> null
    }

The HasPlaceholder doesn't have to be a mixin interface, it could be just an interface with single method, String getPlaceholder(). TextField, TextArea, PasswordField, ComboBox, DatePicker can implement the interface directly; Input needs to modify the return type from Optional to String.

A simple interface would do:

public interface HasPlaceholder {
    /**
     * A hint to the user of what can be entered in the component.
     *
     * @return the {@code placeholder} property from the webcomponent
     */
    public String getPlaceholder();
     /**
     * A hint to the user of what can be entered in the control.
     * @param placeholder
     *            the String value to set
     */
    public void setPlaceholder(String placeholder);
}

@mvysny mvysny changed the title Create HasPlaceholder mixin Create HasPlaceholder interface Mar 8, 2019
@vaadin-miki
Copy link
Contributor

bumping this, as it would greatly help
reasoning similar to #3241

@Vinetos
Copy link

Vinetos commented Dec 12, 2022

Hello, I would have this feature too.
I saw that HasPlaceholder has existed in previous version (Vaadin 13).

I need it because I'm rewriting part of component in a 'fluent' way (.with pattern) and all xxxFields, ComboBoxes, TextAreas implements this.

It should be applied to the interfaces HasValue.

@vaadin-miki
Copy link
Contributor

@Vinetos (and everyone else looking to have this functionality implemented, for that matter) - the interface HasPlaceholder (and a mixin for .withPlaceholder()) is present in SuperFields (https://github.com/vaadin-miki/super-fields/), the add-on that I am an author of

so if you do not mind using a third-party add-on, feel free to use SuperFields while this issue is still in the works :)

mvysny added a commit that referenced this issue Nov 22, 2023
* feature: Implement HasPlaceholder. Fixes #4068

* refactoring!: Make Input implement HasPlaceholder

* chore: format

* chore: add copyright header

* feat: InputTextElement now implements HasPlaceholder
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 24.3.0.alpha6 and is also targeting the upcoming stable 24.3.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

5 participants