A11y: A label that describes the button
Icon Button
IconButton composes the Button
component except that it renders only an icon.
Since IconButton
only renders an icon, you must pass the aria-label
prop, so
screen readers can give meaning to the button.
Import#
import { IconButton } from "@chakra-ui/react"
Usage#
<DarkMode><IconButton aria-label="Search database" icon={<SearchIcon />} /></DarkMode>
<IconButton aria-label="Search database" icon={<SearchIcon />} />
Button Colors#
The IconButton
component accepts most of the props from the Button
component, so we can use colorScheme
prop to change the color of the button.
<DarkMode><IconButtoncolorScheme="blue"aria-label="Search database"icon={<SearchIcon />}/></DarkMode>
<IconButtoncolorScheme="blue"aria-label="Search database"icon={<SearchIcon />}/>
Button Sizes#
Like the Button component
, pass the size
prop to change the size of the
button.
<DarkMode><IconButtoncolorScheme="teal"aria-label="Call Fred"size="lg"icon={<PhoneIcon />}/>{" "}</DarkMode>
<IconButtoncolorScheme="teal"aria-label="Call Fred"size="lg"icon={<PhoneIcon />}/>
Button Variants#
Like the Button
component, pass the variant
prop to change the style of the
button.
<DarkMode><IconButtonvariant="outline"colorScheme="teal"aria-label="Send email"icon={<EmailIcon />}/>{" "}</DarkMode>
<IconButtonvariant="outline"colorScheme="teal"aria-label="Send email"icon={<EmailIcon />}/>
With custom icon#
You can also use icons from popular libraries like react-icons and just pass it into the button.
<DarkMode><IconButtonvariant="outline"colorScheme="teal"aria-label="Call Fred"fontSize="20px"icon={<MdPhone />}/>{" "}</DarkMode>
<IconButtonvariant="outline"colorScheme="teal"aria-label="Call Fred"fontSize="20px"icon={<MdPhone />}/>
Props#
aria-label
required
aria-label
required
string
colorScheme
colorScheme
"whiteAlpha" | "blackAlpha" | "gray" | "red" | "orange" | "yellow" | "green" | "teal" | "blue" | "cyan" | "purple" | "pink" | "linkedin" | "facebook" | "messenger" | "whatsapp" | "twitter" | "telegram"
"gray"
icon
icon
The icon to be used in the button.
React.ReactElement
isActive
isActive
If true
, the button will be styled in its active state.
boolean
isDisabled
isDisabled
If true
, the button will be disabled.
boolean
isLoading
isLoading
If true
, the button will show a spinner.
boolean
isRound
isRound
If true
, the button will be perfectly round. Else, it'll be slightly round
boolean
size
size
"sm" | "md" | "lg" | "xs"
"md"
spinner
spinner
Replace the spinner component when isLoading
is set to true
React.ReactElement
variant
variant
"link" | "outline" | "solid" | "ghost" | "unstyled"
"solid"
© 2021, Made with ❤️ by Creative Tim & Simmmple for a better web