ButtonLink
To implement ButtonLink component into your project you’ll need to add the import:
import ButtonLink from "@kiwicom/orbit-components/lib/ButtonLink";
After adding import into your project you can use it simply like:
<ButtonLink>Hello World!</ButtonLink>
Props
Table below contains all types of the props available in ButtonLink component.
| Name | Type | Default | Description | 
|---|---|---|---|
| ariaControls | string | Id of the element the button controls. | |
| ariaExpanded | boolean | Tells screen reader the controlled element from ariaControlsis expanded | |
| asComponent | string \| () => React.Element | "button" | The component used for the root node. | 
| centered | boolean | false | Can only be used when fullWidthis true and ificonLeftand/oriconRightare defined. Ifcenteredprop istrue, the Button will center everything. | 
| circled | boolean | false | If true, the ButtonLink will have circular shape. | 
| children | React.Node | The content of the ButtonLink. See Functional specs | |
| compact | boolean | false | If true, the ButtonLink will not have horizontal paddings. | 
| disabled | boolean | false | If true, the ButtonLink will be disabled. | 
| download | boolean \| string | Can only be used when hrefis defined. Adds thedownloadattribute to the anchor element. | |
| dataTest | string | Optional prop for testing purposes. | |
| id | string | Set idforButtonLink | |
| external | boolean | false | If true, the ButtonLink opens link in a new tab. See Functional specs | 
| fullWidth | boolean | false | If true, the ButtonLink will grow up to the full width of its container. | 
| href | string | The URL of link to open when ButtonLink is clicked. See Functional specs | |
| iconLeft | React.Node | The displayed icon on the left. | |
| iconRight | React.Node | The displayed icon on the right. | |
| onClick | event => void \| Promise | Function for handling onClick event. | |
| ref | func | Prop for forwarded ref of the Button. | |
| ref | string | Specifies the ref of an element. See Functional specs | |
| role | string | Specifies the role of an element. | |
| size | enum | "normal" | The size of the ButtonLink. | 
| spaceAfter | enum | Additional margin-bottomafter component. | |
| submit | boolean | false | If true, the Button will havetype="submit"attribute, otherwisetype="button". | 
| tabIndex | string \| number | Specifies the tab order of an element. | |
| title | string | Adds aria-label. | |
| type | enum | "primary" | The type of ButtonLink. | 
| width | string | The width of the ButtonLink. Can be any string - 100px,20%. | 
enum
| type | size | spaceAfter | 
|---|---|---|
| "primary" | "small" | "none" | 
| "secondary" | "normal" | "smallest" | 
| "critical" | "large" | "small" | 
| "normal" | ||
| "medium" | ||
| "large" | ||
| "largest" | 
Functional specs
- When the - externalis specified,- noopenervalue will be automatically added to attribute- relfor security reason. Read more about it here.
- By passing the - hrefprop into Button, it will render into- aelement. If you pass- componentprop it will override this logic.
- If you want to render Icon only ButtonLink, you just need to let - childrenprop empty and set up any- iconyou want to use.
- If you want to use the - asComponentprop then YourComponent should accept at least- className. Otherwise it won’t be rendered with proper styling, e.g.:
const YourComponent = props => <div {...props} /><ButtonLink asComponent={YourComponent}>Title</ButtonLink>
If you specify the children of YourComponent component, it will override the children prop of Button component, e.g.:
const YourComponent = props => <div {...props}>YourComponent</div><ButtonLink asComponent={YourComponent}>Title</ButtonLink>
This example will render ButtonLink in div with children YourComponent and not Title.
Accessibility
If you use ButtonLink without href so it’s rendered as a <button> HTML element, then you can use props below. In case you are passing href and element is rendered as <a> then it should be treated as a link and ariaControls, ariaExpanded shouldn’t be useful.
- Use - ariaControlsprop to add- aria-controlsattribute to establish the relationship between button and element which is controlled by it.- aria-controlsworks only with a unique- idof an element.
- Use - ariaExpandsprop to add- aria-expandsto indicate screenreaders, that element controlled by button through- ariaControlsis expanded or not.
- Use - disabledprop to indicate users that button is inactive and they can’t interact with it.
- Use - roleand- tabIndexwhen you are rendering- ButtonLinkto non-actionable HTML element as- divor- span. However, this should be done only in edge-cases as it is anti-pattern behavior.
- Use - titleto add- aria-labelwhen you need to add extra informations to screen readers or there is no- childrenpresented to be used as label.