Skip to content

HorizontalLayout addComponentToIndex uses default slot if index>count #8408

@rolfsmeds

Description

@rolfsmeds

Description

When adding elements to a HorizontalLayout with addComponentToIndex, if the index provided is greater than the last existing index in the layout, the element always ends up in the left/default slot.

This is clearly caused by the slot being simply ignored if no component exists at the given index:

Expected outcome

Would expect the element to be placed in whatever slot the last (i.e. end-most) existing element is in.

Minimal reproducible example

One would expect this to place Button 4 in the end slot, but it ends up in the left/default slot:

HorizontalLayout hz = new HorizontalLayout();
hz.add(new Button("1"));
hz.addToEnd(new Button("2"));
hz.addToEnd(new Button("3"));
hz.addComponentAtIndex(hz.getComponentCount()), new Button("4"));

Steps to reproduce

  1. Add one or more components to the middle or end slot of a HorizontalLayout
  2. Add another component using addComponentAtIndex, providing an index >= the current component count
  3. Observe the newly added component being in the left/default slot instead of after the last previously added component

Environment

Vaadin version(s): V25.0

Browsers

Issue is not browser related

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions