diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/elements/AnchorElement.java b/domino-ui/src/main/java/org/dominokit/domino/ui/elements/AnchorElement.java index 41beb282..1b89566f 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/elements/AnchorElement.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/elements/AnchorElement.java @@ -80,4 +80,43 @@ public AnchorElement removeHref() { removeAttribute("href"); return this; } + + /** + * Sets the target for this href, if null or empty, remove the target attribute. + * + * @param target one of {@code _self}, {@code _blank}, {@code _parent}, {@code _top}, {@code + * _unfencedTop}, + * @return The current {@link AnchorElement} instance. + */ + public AnchorElement setTarget(String target) { + if (isNull(target) || target.trim().isEmpty()) { + removeAttribute("target"); + } else { + setAttribute("target", target); + } + return this; + } + + /** + * Sets the target for this href, if null or empty, remove the target attribute. + * + * @param target {@link AnchorTarget} + * @return The current {@link AnchorElement} instance. + */ + public AnchorElement setTarget(AnchorTarget target) { + if (isNull(target)) { + removeAttribute("target"); + } else { + setAttribute("target", target.name()); + } + return this; + } + + public enum AnchorTarget { + _self, + _blank, + _parent, + _top, + _unfencedTop; + } }