com.vaadin.flow.component.html.
Class Anchor
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.HtmlComponent
-
- com.vaadin.flow.component.HtmlContainer
-
- com.vaadin.flow.component.html.Anchor
-
All Implemented Interfaces:
AttachNotifier
,BlurNotifier<Anchor>
,DetachNotifier
,Focusable<Anchor>
,FocusNotifier<Anchor>
,HasAriaLabel
,HasComponents
,HasElement
,HasEnabled
,HasSize
,HasStyle
,HasText
,Serializable
@Tag("a") public class Anchor extends HtmlContainer implements Focusable<Anchor>, HasAriaLabel
Component representing an
<a>
element.Since:
1.0
Author:
Vaadin Ltd
See Also:
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
BlurNotifier.BlurEvent<C extends Component>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
FocusNotifier.FocusEvent<C extends Component>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText
HasText.WhiteSpace
-
-
Constructor Summary
Constructors Constructor Description Anchor()
Creates a new empty anchor component.
Anchor(AbstractStreamResource href, String text)
Creates an anchor component with the given text content and stream resource.
Anchor(String href, Component... components)
Creates an anchor component with the given href and components as children of this component.
Anchor(String href, String text)
Creates an anchor component with the given text content and href.
Anchor(String href, String text, AnchorTarget target)
Creates an anchor component with the given target, text content and href.
-
Method Summary
All Methods Modifier and Type Method Description String
getHref()
Gets the URL that this anchor links to.
Optional<String>
getTarget()
Gets the target window, tab or frame name for this anchor.
AnchorTargetValue
getTargetValue()
Gets the target window, tab or frame value for this anchor.
void
onEnabledStateChanged(boolean enabled)
Handle component enable state when the enabled state changes.
void
removeHref()
Removes href attribute.
void
setHref(AbstractStreamResource href)
Sets the URL that this anchor links to with the URL of the given
StreamResource
.void
setHref(String href)
Sets the URL that this anchor links to.
void
setTarget(AnchorTargetValue target)
Sets the target window, tab or frame for this anchor.
void
setTarget(String target)
Sets the target window, tab or frame for this anchor.
-
Methods inherited from class com.vaadin.flow.component.HtmlComponent
getTitle, setTitle
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, scrollIntoView, set, setElement, setId, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
Methods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
-
Methods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListener
-
Methods inherited from interface com.vaadin.flow.component.HasAriaLabel
getAriaLabel, setAriaLabel
-
Methods inherited from interface com.vaadin.flow.component.HasComponents
add, add, addComponentAsFirst, addComponentAtIndex, remove, removeAll
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
-
Methods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
-
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Methods inherited from interface com.vaadin.flow.component.HasText
getText, getWhiteSpace, setText, setWhiteSpace
-
-
-
-
Constructor Detail
-
Anchor
public Anchor()
Creates a new empty anchor component.
-
Anchor
public Anchor(String href, String text)
Creates an anchor component with the given text content and href.
Parameters:
href
- the href to settext
- the text content to setSee Also:
-
Anchor
public Anchor(String href, String text, AnchorTarget target)
Creates an anchor component with the given target, text content and href.
Parameters:
href
- the href to settext
- the text content to settarget
- the target window, tab or frameSee Also:
setHref(String)
,HasText.setText(String)
,setTarget(AnchorTargetValue)
-
Anchor
public Anchor(AbstractStreamResource href, String text)
Creates an anchor component with the given text content and stream resource.
Parameters:
href
- the resource value, not nulltext
- the text content to setSee Also:
-
Anchor
public Anchor(String href, Component... components)
Creates an anchor component with the given href and components as children of this component.
Parameters:
href
- the href to setcomponents
- the components to addSee Also:
setHref(AbstractStreamResource)
,HasComponents.add(Component...)
-
-
Method Detail
-
setHref
public void setHref(String href)
Sets the URL that this anchor links to.
A disabled Anchor removes the attribute from the HTML element, but it is stored (and reused when enabled again) in the server-side component.
Use the method
removeHref()
to remove the href attribute instead of setting it to an empty string.Parameters:
href
- the href to setSee Also:
-
removeHref
public void removeHref()
Removes href attribute.
See Also:
-
setHref
public void setHref(AbstractStreamResource href)
Sets the URL that this anchor links to with the URL of the given
StreamResource
.Parameters:
href
- the resource value, not null
-
getHref
public String getHref()
Gets the URL that this anchor links to.
Returns:
the href value, or
""
if no href has been setSee Also:
-
onEnabledStateChanged
public void onEnabledStateChanged(boolean enabled)
Description copied from class:
Component
Handle component enable state when the enabled state changes.
By default this sets or removes the 'disabled' attribute from the element. This can be overridden to have custom handling.
Overrides:
onEnabledStateChanged
in classComponent
Parameters:
enabled
- the new enabled state of the component
-
setTarget
public void setTarget(String target)
Sets the target window, tab or frame for this anchor. The target is either the
window.name
of a specific target, or one of these special values:_self
: Open the link in the current context. This is the default behavior._blank
: Opens the link in a new unnamed context._parent
: Opens the link in the parent context, or the current context if there is no parent context._top
: Opens the link in the top most grandparent context, or the current context if there is no parent context.
Parameters:
target
- the target value, or""
to remove the target value
-
getTarget
public Optional<String> getTarget()
Gets the target window, tab or frame name for this anchor.
Returns:
an optional target, or an empty optional if no target has been set
See Also:
-
setTarget
public void setTarget(AnchorTargetValue target)
Sets the target window, tab or frame for this anchor. The target may be the one of these special values:
AnchorTarget.DEFAULT
: Removes the target value. This has the same effect as setting the target toAnchorTarget.SELF
.AnchorTarget.SELF
: Opens the link in the current context.AnchorTarget.BLANK
: Opens the link in a new unnamed context.AnchorTarget.PARENT
: Opens the link in the parent context, or the current context if there is no parent context.AnchorTarget.TOP
: Opens the link in the top most grandparent context, or the current context if there is no parent context.
Parameters:
target
- the target value, not null
-
getTargetValue
public AnchorTargetValue getTargetValue()
Gets the target window, tab or frame value for this anchor.
Returns:
the target window value , or
AnchorTarget.DEFAULT
if no target has been setSee Also:
-
-