Class Breadcrumbs

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.breadcrumbs.Breadcrumbs
All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasAriaLabel, HasComponentsOfType<BreadcrumbsItem>, HasElement, HasEnabled, HasSize, HasStyle, HasTheme, HasThemeVariant<BreadcrumbsVariant>, Serializable

@Tag("vaadin-breadcrumbs") @NpmPackage(value="@vaadin/breadcrumbs", version="25.2.0") @JsModule("@vaadin/breadcrumbs/src/vaadin-breadcrumbs.js") public class Breadcrumbs extends Component implements HasSize, HasStyle, HasAriaLabel, HasComponentsOfType<BreadcrumbsItem>, HasThemeVariant<BreadcrumbsVariant>
Breadcrumbs is a component for displaying a navigation trail that shows the user's location within a hierarchy of pages.

This component is experimental and needs to be enabled with the com.vaadin.experimental.breadcrumbsComponent feature flag.

Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • Breadcrumbs

      public Breadcrumbs()
      Creates a new breadcrumbs component in Breadcrumbs.Mode.ROUTER mode.
    • Breadcrumbs

      public Breadcrumbs(Breadcrumbs.Mode mode)
      Creates a new breadcrumbs component in the given mode.
      Parameters:
      mode - the mode that determines how the trail is populated, not null
  • Method Details

    • getMode

      public Breadcrumbs.Mode getMode()
      Gets the mode that determines how the breadcrumb trail is populated.
      Returns:
      the current mode
    • setMode

      public void setMode(Breadcrumbs.Mode newMode)
      Sets the mode that determines how the breadcrumb trail is populated.

      Switching to a different mode discards the existing children: both the ROUTER -> MANUAL and MANUAL -> ROUTER transitions clear the current trail so the new mode can start fresh. Setting the mode to its current value is a no-op and leaves the children untouched.

      Parameters:
      newMode - the mode that determines how the trail is populated, not null
      Throws:
      IllegalStateException - if a children binding set via bindChildren is active; such a binding takes over the trail and cannot be handed back to component-controlled population
    • add

      public void add(BreadcrumbsItem... components)
      Description copied from interface: HasComponentsOfType
      Adds the given components as children of this component.

      In case any of the specified components has already been added to another parent, it will be removed from there and added to this one.

      Specified by:
      add in interface HasComponentsOfType<BreadcrumbsItem>
      Parameters:
      components - the components to add
    • add

      public void add(Collection<BreadcrumbsItem> components)
      Description copied from interface: HasComponentsOfType
      Adds the given components as children of this component.

      In case any of the specified components has already been added to another parent, it will be removed from there and added to this one.

      Specified by:
      add in interface HasComponentsOfType<BreadcrumbsItem>
      Parameters:
      components - the components to add
    • remove

      public void remove(BreadcrumbsItem... components)
      Description copied from interface: HasComponentsOfType
      Removes the given child components from this component.
      Specified by:
      remove in interface HasComponentsOfType<BreadcrumbsItem>
      Parameters:
      components - the components to remove
    • remove

      public void remove(Collection<BreadcrumbsItem> components)
      Description copied from interface: HasComponentsOfType
      Removes the given child components from this component.
      Specified by:
      remove in interface HasComponentsOfType<BreadcrumbsItem>
      Parameters:
      components - the components to remove
    • removeAll

      public void removeAll()
      Description copied from interface: HasComponentsOfType
      Removes all contents from this component, including child components, text content as well as child elements that have been added directly to this component using the Element API. It also removes the children added only at the client-side.
      Specified by:
      removeAll in interface HasComponentsOfType<BreadcrumbsItem>
    • addComponentAsFirst

      public void addComponentAsFirst(BreadcrumbsItem component)
      Description copied from interface: HasComponentsOfType
      Adds the given component as the first child of this component.

      In case the specified component has already been added to another parent, it will be removed from there and added to this one.

      Specified by:
      addComponentAsFirst in interface HasComponentsOfType<BreadcrumbsItem>
      Parameters:
      component - the component to add, value should not be null
    • addComponentAtIndex

      public void addComponentAtIndex(int index, BreadcrumbsItem component)
      Description copied from interface: HasComponentsOfType
      Adds the given component as a child of this component at the specific index.

      In case the specified component has already been added to another parent, it will be removed from there and added to this one.

      Specified by:
      addComponentAtIndex in interface HasComponentsOfType<BreadcrumbsItem>
      Parameters:
      index - the index, where the component will be added. The index must be non-negative and may not exceed the children count
      component - the component to add, value should not be null
    • replace

      public void replace(BreadcrumbsItem oldComponent, BreadcrumbsItem newComponent)
      Description copied from interface: HasComponentsOfType
      Replaces the component in the container with another one without changing position. This method replaces a component with another one is such a way that the new component overtakes the position of the old component. If the old component is not in the container, the new component is added to the container. If both components are already in the container, their positions are swapped. Component attach and detach events should be taken care as with add and remove.
      Specified by:
      replace in interface HasComponentsOfType<BreadcrumbsItem>
      Parameters:
      oldComponent - the old component that will be replaced. Can be null, which will make the newComponent to be added to the layout without replacing any other
      newComponent - the new component to be replaced. Can be null, which will make the oldComponent to be removed from the layout without adding any other
    • bindChildren

      public <V extends @Nullable Object, S extends Signal<V>> void bindChildren(Signal<List<S>> list, SerializableFunction<S,BreadcrumbsItem> childFactory)
      Description copied from interface: HasComponentsOfType
      Binds a list Signal to this component using a child component factory. Each item Signal in the list corresponds to a child component within this component.

      This component is automatically updated to reflect the structure of the list. Changes to the list, such as additions, removals, or reordering, will update this component's children accordingly.

      This component must not contain any children in the default slot (i.e. without a slot attribute) that are not part of the list. If this component has existing default-slot children when this method is called, or if it contains unrelated default-slot children after the list changes, an IllegalStateException will be thrown. Named-slot children are allowed and can be added or removed freely while the binding is active.

      New child components are created using the provided childFactory function. This function takes a Signal from the list and returns a corresponding child component. It shouldn't return null. The Signal can be further bound to the returned component as needed. Note that childFactory is run inside a Effect, and therefore Signal.get() calls makes effect re-run automatically on signal value change.

      Example of usage:

       SharedListSignal<String> taskList = new SharedListSignal<>(String.class);
      
       UnorderedList component = new UnorderedList();
      
       component.bindChildren(taskList, ListItem::new);
       

      Note: The default implementation adds children directly to the component?s element using the Element API and does not invoke HasComponentsOfType.add(Component...). Components that override add or manage children indirectly must override this method to provide a suitable implementation or explicitly disable it.

      Specified by:
      bindChildren in interface HasComponentsOfType<BreadcrumbsItem>
      Type Parameters:
      V - the value type of the Signals in the list
      S - the type of the Signals in the list
      Parameters:
      list - list signal to bind to the parent, must not be null
      childFactory - factory to create new component, must not be null
    • onAttach

      protected void onAttach(AttachEvent attachEvent)
      Description copied from class: Component
      Called when the component is attached to a UI.

      This method is invoked before the AttachEvent is fired for the component. Make sure to call super.onAttach when overriding this method.

      Overrides:
      onAttach in class Component
      Parameters:
      attachEvent - the attach event
    • onDetach

      protected void onDetach(DetachEvent detachEvent)
      Description copied from class: Component
      Called when the component is detached from a UI.

      This method is invoked before the DetachEvent is fired for the component.

      Make sure to call super.onDetach when overriding this method.

      Overrides:
      onDetach in class Component
      Parameters:
      detachEvent - the detach event
    • getI18n

      public Breadcrumbs.BreadcrumbsI18n getI18n()
      Gets the internationalization object previously set for this component.

      NOTE: Updating the instance that is returned from this method will not update the component if not set again using setI18n(BreadcrumbsI18n)

      Returns:
      the i18n object or null if no i18n object has been set
    • setI18n

      public void setI18n(Breadcrumbs.BreadcrumbsI18n i18n)
      Sets the internationalization properties for this component.
      Parameters:
      i18n - the i18n object, not null