Class Anchor
- All Implemented Interfaces:
AttachNotifier,BlurNotifier<Anchor>,DetachNotifier,Focusable<Anchor>,FocusNotifier<Anchor>,HasAriaLabel,HasComponents,HasElement,HasEnabled,HasSize,HasStyle,HasText,Serializable
<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
ConstructorsConstructorDescriptionAnchor()Creates a new empty anchor component.Anchor(AbstractStreamResource href, String text) Deprecated, for removal: This API element is subject to removal in a future version.Anchor(DownloadHandler downloadHandler, AttachmentType attachmentType, String text) Creates an anchor component with the given text content and a callback that handles data download from the server to the client when clicking an anchor.Anchor(DownloadHandler downloadHandler, String text) Creates an anchor component with the given text content and a callback that handles data download from the server to the client when clicking an anchor.Creates an anchor component with the given href and components as children of this component.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
Modifier and TypeMethodDescriptiongetHref()Gets the URL that this anchor links to.Gets the target window, tab or frame name for this anchor.Gets the target window, tab or frame value for this anchor.booleanCheck if the anchor target will be downloaded for a click.booleanvoidonEnabledStateChanged(boolean enabled) Handle component enable state when the enabled state changes.voidRemoves href attribute.voidsetDownload(boolean download) Set the download state of the anchor.voidDeprecated, for removal: This API element is subject to removal in a future version.usesetHref(DownloadHandler)insteadvoidsetHref(DownloadHandler downloadHandler) Sets the URL that this anchor links to and that is bound to a givenDownloadHandlercallback on the server for handling data download from the server to the client when clicking an anchor.voidsetHref(DownloadHandler downloadHandler, AttachmentType attachmentType) Sets the URL that this anchor links to and that is bound to a givenDownloadHandlercallback on the server for handling data download from the server to the client when clicking an anchor.voidSets the URL that this anchor links to.voidsetRouterIgnore(boolean ignore) The routing mechanism in Vaadin by default intercepts all anchor elements with relative URL.voidsetTarget(AnchorTargetValue target) Sets the target window, tab or frame for this anchor.voidSets the target window, tab or frame for this anchor.Methods inherited from class com.vaadin.flow.component.HtmlComponent
getTitle, setTitleMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasAriaLabel
getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledByMethods inherited from interface com.vaadin.flow.component.HasComponents
add, add, add, addComponentAsFirst, addComponentAtIndex, remove, remove, removeAllMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods 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, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasText
getText, getWhiteSpace, setText, setWhiteSpace
-
Constructor Details
-
Anchor
public Anchor()Creates a new empty anchor component. -
Anchor
Creates an anchor component with the given text content and href.- Parameters:
href- the href to settext- the text content to set- See Also:
-
Anchor
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 frame- See Also:
-
Anchor
Deprecated, for removal: This API element is subject to removal in a future version.useAnchor(DownloadHandler, String)insteadCreates an anchor component with the given text content and stream resource.- Parameters:
href- the resource value, not nulltext- the text content to set- See Also:
-
Anchor
Creates an anchor component with the given text content and a callback that handles data download from the server to the client when clicking an anchor.Sets the 'download' attribute for link when given a non-inline handler implementing AbstractDownloadHandler.
For custom handlers the mode
AttachmentType.DOWNLOADwill be set.- Parameters:
downloadHandler- the callback that handles data download, not nulltext- the text content to set- See Also:
-
Anchor
Creates an anchor component with the given text content and a callback that handles data download from the server to the client when clicking an anchor.Sets the 'download' attribute for link when given a non-inline handler implementing AbstractDownloadHandler.
LinkMode determines if the attribute `download` should be set or not.
AttachmentType.DOWNLOADwill set the download attribute, where asAttachmentType.INLINEwill remove it.- Parameters:
downloadHandler- the callback that handles data download, not nullattachmentType- set the correct attribute for anchor according to given mode,nullwill set type toAttachmentType.DOWNLOADtext- the text content to set- See Also:
-
Anchor
Creates an anchor component with the given href and components as children of this component.- Parameters:
href- the href to setcomponents- the components to add- See Also:
-
-
Method Details
-
setHref
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 set- See Also:
-
removeHref
public void removeHref()Removes href attribute.- See Also:
-
setHref
Deprecated, for removal: This API element is subject to removal in a future version.usesetHref(DownloadHandler)insteadSets the URL that this anchor links to with the URL of the givenStreamResource.- Parameters:
href- the resource value, not null
-
setHref
Sets the URL that this anchor links to and that is bound to a givenDownloadHandlercallback on the server for handling data download from the server to the client when clicking an anchor.Sets the 'download' attribute for link when given a non-inline handler implementing AbstractDownloadHandler.
- Parameters:
downloadHandler- the callback that handles data download, not null
-
setHref
Sets the URL that this anchor links to and that is bound to a givenDownloadHandlercallback on the server for handling data download from the server to the client when clicking an anchor.LinkMode determines if the attribute `download` should be set or not.
AttachmentType.DOWNLOADwill set the download attribute, where asAttachmentType.INLINEwill remove it.- Parameters:
downloadHandler- the callback that handles data download, not nullattachmentType- set the correct attribute for anchor according to given mode,nullwill set the type toAttachmentType.DOWNLOAD
-
setDownload
public void setDownload(boolean download) Set the download state of the anchor.truewill add the download attribute making the anchor target to be downloaded on click.falsewill remove the download attribute.- Parameters:
download-trueto add the 'download' attribute andfalseto remove it
-
isDownload
public boolean isDownload()Check if the anchor target will be downloaded for a click.- Returns:
trueif download is set for this anchor
-
setRouterIgnore
public void setRouterIgnore(boolean ignore) The routing mechanism in Vaadin by default intercepts all anchor elements with relative URL. This method can be used make the router ignore this anchor and this way make this anchor behave normally and cause a full page load.- Parameters:
ignore- true if this link should not be intercepted by the single-page web application routing mechanism in Vaadin.
-
isRouterIgnore
public boolean isRouterIgnore()- Returns:
- true if this anchor should be ignored by the Vaadin router and behave normally.
-
getHref
Gets the URL that this anchor links to.- Returns:
- the href value, or
""if no href has been set - See Also:
-
onEnabledStateChanged
public void onEnabledStateChanged(boolean enabled) Description copied from class:ComponentHandle 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:
onEnabledStateChangedin classComponent- Parameters:
enabled- the new enabled state of the component
-
setTarget
Sets the target window, tab or frame for this anchor. The target is either thewindow.nameof 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
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
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
Gets the target window, tab or frame value for this anchor.- Returns:
- the target window value , or
AnchorTarget.DEFAULTif no target has been set - See Also:
-
Anchor(DownloadHandler, String)instead