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

@Id mapped Tabs should be able to selected @Id mapped Tab #7622

Open
Artur- opened this issue Feb 18, 2020 · 3 comments
Open

@Id mapped Tabs should be able to selected @Id mapped Tab #7622

Artur- opened this issue Feb 18, 2020 · 3 comments

Comments

@Artur-
Copy link
Member

Artur- commented Feb 18, 2020

Given main-view.js

import { PolymerElement, html } from "@polymer/polymer";

class MainView extends PolymerElement {
  static get template() {
    return html`
      <vaadin-button id="button">Go</vaadin-button>
      <vaadin-tabs id="tabs">
        <vaadin-tab>First</vaadin-tab>
        <vaadin-tab id="secondTab">Second</vaadin-tab>
        <vaadin-tab>Third</vaadin-tab>
      </vaadin-tabs>
    `;
  }
}

customElements.define("main-view", MainView);

and MainView.java

@Route
@JsModule("./main-view.js")
@Tag("main-view")
public class MainView extends PolymerTemplate<TemplateModel> {

    @Id
    private Button button;
    @Id
    private Tabs tabs;
    @Id
    private Tab secondTab;

    public MainView() {
        button.addClickListener(e -> {
            tabs.setSelectedTab(secondTab);
        });
    }

}

You would expect a button click would select the second tab.

Currently an exception is printed instead

java.lang.IllegalArgumentException: Tab to select must be a child: Tab{}
	at com.vaadin.flow.component.tabs.Tabs.setSelectedTab(Tabs.java:381) ~[vaadin-tabs-flow-2.0.4.jar:na]
	at com.example.app.MainView.lambda$0(MainView.java:38) ~[classes/:na]
@Legioth
Copy link
Member

Legioth commented Feb 18, 2020

From an implementation point of view, this would at the very least mean that when one @Id element is the child of another @Id element, then Flow should set up a parent-child relationship between them.

It may also be necessary to define elements (but not component instances) for the siblings so that the relative position of the child can be determined.

@caalador
Copy link
Contributor

Also note the issue vaadin/vaadin-tabs-flow#67

@pleku
Copy link
Contributor

pleku commented Mar 9, 2020

As said in vaadin/vaadin-tabs-flow#67 (comment) we were not going to do anything about this and would simply not recommend using @Id mapping with Tabs.

My bet is that this is quite big task to do, and I'm not sure if this is just about what @Legioth said about the parent-child relationship but also would need changes to the Tabs component.

So the question would be: do we really need to fix this ? How did you come up with this use case @Artur- ?

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

No branches or pull requests

6 participants