Skip to content

Commit

Permalink
fix #966 add findTabByKey to tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Sep 24, 2024
1 parent 20eda8b commit 45e3af5
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
import static java.util.Objects.nonNull;
import static org.dominokit.domino.ui.utils.Domino.*;

import elemental2.dom.DomGlobal;
import elemental2.dom.Element;
import elemental2.dom.HTMLDivElement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import org.dominokit.domino.ui.IsElement;
import org.dominokit.domino.ui.animations.Animation;
Expand Down Expand Up @@ -424,13 +425,20 @@ public TabsPanel activateByKey(String key) {
* @return the current {@link TabsPanel} instance.
*/
public TabsPanel activateByKey(String key, boolean silent) {
tabs.stream()
.filter(tab -> tab.getKey().equalsIgnoreCase(key))
.findFirst()
.ifPresent(tab -> activateTab(tab, silent));
findByKey(key).ifPresent(tab -> activateTab(tab, silent));
return this;
}

/**
* Finds the first tab by the specified key. this is a case-sensitive search
*
* @param key The tab key
* @return Optional of a tab.
*/
public Optional<Tab> findByKey(String key) {
return tabs.stream().filter(tab -> Objects.equals(tab.getKey(), key)).findFirst();
}

/**
* Checks if the auto-activation feature is enabled. When auto-activation is enabled, the first
* tab added to the tabs panel will automatically be set as active.
Expand Down

0 comments on commit 45e3af5

Please sign in to comment.