Invokes and communicates an action that will occur
Use primary buttons for actions to complete a task or to move forward in a process such as "Add to cart." There is only one primary action per major page section.
Use secondary buttons for all actions that do not move the user to the next step or require additional user actions such as "Add to wish list" or "Find a campout near you."
Use sale
or dark
for alternative button styling.
Use link
modifier to render a button that is styled like a CdrLink. This can be used to create links with the padding and sizing options of a button. Can be used with the tag
property set to the default "button"
or "a"
. For rendering a link inline with text, use CdrLink. To render a button that behaves like a link, use a CdrButton with link tag.
Pair an icon with text to improve recognition about an object or action.
Use icons to visually communicate an object or action in a limited space. Include alternative text to describe what the button does.
Use with-background
property in conjunction with the icon-only
property to make icon buttons more identifiable. Include alternative text to describe what the button does.
For buttons that trigger asynchronous actions, use the click
event and dynamic properties in order to change the label or state of a button.
Displays at full width of its container.
For a CdrButton that looks like a button but behaves like a link, set tag="a"
and pass an href
.
Change the button size based on where the button is used. The default size is medium.
Many WCAG requirements are contextual to their implementation. To ensure that usage of this component complies with accessibility guidelines you are responsible for the following:
aria-label
text that describes the button's actionaria-describedby
set to the ID
of the element containing the description.aria-pressed
state. When the button is toggled on, the value of this state is true, and when toggled off, the state is false.aria-label
might read: "Shop our <specific advertising category> now"cdr-sr-only
class<cdr-cta>
Start here <span class="cdr-sr-only">for help finding the proper sleeping bag</span>
</cdr-cta>
tag
set to "a"
, always providing an href
attribute. Empty href
attributes are not considered true links
This component has no specific WCAG compliance attributes built into the control. It is possibile to define this component as a link or button:
div
or input
elementsrole="button"
to the CdrButton componenttag="a"
and href
when navigating to another page on the siteThree button sizes are available: Small, Medium, and Large. Medium is the default size.
Generally, buttons should be sized based on their content and used to convey the importance of actions.
When stacking buttons vertically:
When arranging buttons horizontally:
When grouping buttons, match button sizes either horizontally or vertically.
To construct consistent and universal Calls to Action across the site:
When making decisions about whether to use a link or a button, consider the following:
Links | Buttons |
---|---|
Answers the question, "Where can I go" | Answers the question, "What can I do" |
Search engine crawlers can follow anchors for links (<a> ) | Search engine crawlers cannot follow links that are submitted by input or button |
Default keyboard behavior is triggered using the Enter key | Default keyboard behavior is triggered using the Space or Enter key |
Cannot be disabled like buttons but can be made inert with tabindex="-1" and aria-hidden="true" | Can be disabled with disabled attribute |
Apply the following use cases when deciding when to use links as anchors or buttons:
Links | Buttons |
---|---|
Navigating user to a new page or view | Toggling a display to full screen |
Changing the URL | Opening a modal window |
Causing a browser redraw or refresh | Triggering a popup menu |
Supporting internal page jumps | Can be disabled with disabled attribute |
This component will bind any attribute that a native HTML button element (opens new window) accepts.
tag
name
string
type
'button'
default
Renders CdrButton as a <button> or <a> element. When using the value of <a>, this element renders as an anchor link. Possible values: { 'button' | 'a' }
type
name
string
type
'button'
default
Sets the button type. Possible values: { 'button' | 'submit' | 'reset' }
fullWidth
name
boolean
type
false
default
Sets button width to 100%. Setting this value to true will set the button width to 100% of the parent container. Use the 'fullWidth' prop with the 'size' prop to control top and bottom padding.
size
name
string
type
'medium'
default
Sets the button size; values can target responsive breakpoints. Breakpoint values are: xs, sm, md, and lg. Examples: { 'small' | 'medium' | 'large' | 'large@sm' }
iconOnly
name
boolean
type
false
default
Renders an 'icon-only' button. When this value is true, it will override the size and 'responsiveSize' props. Can be used in conjunction with 'with-background'
withBackground
name
boolean
type
false
default
Renders an 'icon-only' button with a background color and border. Must be used in conjunction with the 'iconOnly' prop.
modifier
name
string
type
N/A
default
Modifies the style variant for this component. Possible values: { 'primary' | 'secondary' | 'sale' | 'dark' | 'link'}
Find more information about using Slots in the article Installing Cedar.
default
name
Sets the innerHTML for CdrButton'. This is the readable text of the button. Leave empty if icon-only.
icon
name
Sets the innerHTML for CdrButton icon-only button.
icon-left
name
Sets the innerHTML for CdrButton with icon to the left of text content.
icon-right
name
Sets the innerHTML for CdrButton with icon to the right of text content.
All event listeners are passed through to/from the component.