![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
clickable-box
Advanced tools
React component to add
onClick
to HTML elements without sacrificing accessibility.
It's very hard to remove all styles from HTML button
elements. It's also hard to create clickable div
s that are accessible. This can cause developers to ship inaccessible UI.
The ClickableBox
React component accepts an onClick
prop and an element to render. It returns the element with the onClick
as well as the attributes and event listeners needed to make it as accessible as a button
.
You can install ClickableBox
with npm, Yarn, or pnpm.
npm install clickable-box
yarn add clickable-box
pnpm install clickable-box
Here's how to use ClickableBox
to make a clickable SVG:
// import ClickableBox from 'clickable-box';
<ClickableBox
onClick={this.closeModal}
aria-label="Close modal"
className="icon-button"
>
<CloseIcon />
</ClickableBox>
ClickableBox
will return a span
that looks like this:
<span
// Make the element clickable
onClick={this.closeModal}
// Make the element navigable by keyboard
tabIndex={0}
// Call `this.closeModal` if the user presses either the
// enter or space key while the element is in focus
onKeyDown={...}
// Tell screen readers that the element is a button
role="button"
// All other props are passed through to the element
aria-label="Close modal"
className="icon-button"
>
<CloseIcon />
</span>
The resulting HTML is accessible for users navigating by screen readers, keyboard, and mouse/touch.
There are a few props that are built into ClickableBox
:
prop | type | description |
---|---|---|
onClick | function | defaults to: undefined | The action to perform when the element is pressed |
is | string , React.Element | defaults to: span | The element to render |
disabled | boolean | defaults to: false | Makes element non-interactive, even if onClick is provided |
ref | React.Ref | Provides access to the React element |
You can pass any custom prop as well. This component will forward those props to the rendered element.
a
tag with an href
instead. The anchor tag is semantically correct, allows users to preview the URL, open it in a new tab, and copy the link to their clipboard.button
element with CSS.button
: This is a good sign that you should use a button
element instead.How can I style this with cursor: pointer
?
ClickableBox
accepts all props including className
and style
prop. If you prefer, you can add the cursor style globally with this CSS:
/* Targets all instances of `ClickableBox` */
[role="button"] {
cursor: pointer;
}
What are accessibility best practices for ClickableBox
?
aria-label
to ClickableBox
if children
contains an SVG and no descriptive text. The value of aria-label
should describe the action that will happen if the button is interacted with. It will be announced to users navigating with screen readers.ClickableBox
within an anchor tag or another button. You also shouldn't use an a
or button
in the children
prop.1.1.10
FAQs
Add `onClick` to HTML elements without sacrificing accessibility.
The npm package clickable-box receives a total of 859 weekly downloads. As such, clickable-box popularity was classified as not popular.
We found that clickable-box demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.