Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
@accessible/disclosure
Advanced tools
npm i @accessible/disclosure
An accessible and versatile disclosure component for React
style
objects, anything!Check out the example on CodeSandbox
import * as React from 'react'
import * as Disclosure from '@accessible/disclosure'
const Component = () => (
<Disclosure.Disclosure>
<Disclosure.Trigger>
<button>Open me</button>
</Disclosure.Trigger>
<Disclosure.Target>
<div className='my-disclosure'>
<Disclosure.CloseButton>
<button>Close me</button>
</Disclosure.CloseButton>
<div>I've been disclosed!</div>
</div>
</Disclosure.Target>
</Disclosure.Disclosure>
)
Component | Description |
---|---|
<Disclosure> | This component creates the context for your disclosure target and trigger and contains some configuration options. |
<Target> | This component wraps any React element and turns it into a disclosure target. |
<Trigger> | This component wraps any React element and turns it into a disclosure trigger. |
<CloseButton> | This is a convenience component that wraps any React element and adds an onClick handler to close the disclosure. |
Hook | Description |
---|---|
useDisclosure() | This hook provides the value of the disclosure's DisclosureContextValue object. |
useTarget() | A React hook for creating a headless disclosure target to WAI-ARIA authoring practices. |
useTrigger() | A React hook for creating a headless disclosure trigger to WAI-ARIA authoring practices. |
useCloseButton() | A React hook for creating a headless close button to WAI-ARIA authoring practices. |
This component creates the context for your disclosure target and trigger and contains some configuration options.
Prop | Type | Default | Required? | Description |
---|---|---|---|---|
defaultOpen | boolean | false | No | This sets the default open state of the disclosure. By default the disclosure is closed. |
open | boolean | undefined | No | This creates a controlled disclosure component where the open state of the disclosure is controlled by this property. |
onChange | (open: boolean) => void | undefined | No | This callback is invoked any time the open state of the disclosure changes. |
id | string | undefined | No | By default this component creates a unique id for you, as it is required for certain aria attributes. Supplying an id here overrides the auto id feature. |
children | React.ReactNode | undefined | No | Your disclosure contents and any other children. |
A React hook for creating a headless disclosure target to WAI-ARIA authoring practices.
Argument | Type | Required? | Description |
---|---|---|---|
target | React.RefObject<T> | T | null | Yes | A React ref or HTML element |
options | UseTargetOptions | No | Configuration options |
export interface UseTargetOptions {
/**
* Adds this class name to props when the disclosure is open
*/
openClass?: string
/**
* Adds this class name to props when the disclosure is closed
*/
closedClass?: string
/**
* Adds this style to props when the disclosure is open
*/
openStyle?: React.CSSProperties
/**
* Adds this style to props when the disclosure is closed
*/
closedStyle?: React.CSSProperties
/**
* Prevents the `window` from scrolling when the target is
* focused after opening.
*/
preventScroll?: boolean
/**
* When `true`, this closes the target element when the `Escape`
* key is pressed.
* @default true
*/
closeOnEscape?: boolean
}
interface A11yProps {
readonly 'aria-hidden': string
readonly id: string | undefined
readonly className: string | undefined
readonly style: {
visibility: string
} & React.CSSProperties
}
import * as React from 'react'
import {useTarget} from '@accessible/disclosure'
const MyTarget = () => {
const ref = React.useRef(null)
const a11yProps = useTarget(ref, {preventScroll: true})
return (
<div ref={ref} {...a11yProps}>
I am the disclosure content
</div>
)
}
This component wraps any React element and turns it into a disclosure target.
Prop | Type | Default | Required? | Description |
---|---|---|---|---|
portal | boolean | string | PortalizeProps | false | No | When true this will render the disclosure into a React portal with the id #portals . You can render it into any portal by providing its query selector here, e.g. #foobar , [data-portal=true] , or .foobar . |
closeOnEscape | boolean | true | No | By default the disclosure will close when the Escape key is pressed. You can turn this off by providing false here. |
closedClass | string | undefined | No | This class name will be applied to the child element when the disclosure is closed . |
openClass | string | "disclosure--open" | No | This class name will be applied to the child element when the disclosure is open . |
closedStyle | React.CSSProperties | undefined | No | These styles will be applied to the child element when the disclosure is closed in addition to the default styles that set the target's visibility. |
openStyle | React.CSSProperties | undefined | No | These styles name will be applied to the child element when the disclosure is open in addition to the default styles that set the target's visibility. |
preventScroll | boolean | false | No | When true this will prevent your browser from scrolling the document to bring the newly-focused tab into view. |
children | React.ReactElement | undefined | Yes | The child is cloned by this component and has aria attributes injected into its props as well as the events defined above. |
<Target>
<div className='alert'>Alert</div>
</Target>
// <div
// class="alert"
// aria-hidden="true"
// id="🅰12"
// style="visibility: hidden;"
// >
// Alert
// </div>
A React hook for creating a headless disclosure trigger to WAI-ARIA authoring practices. In addition to providing accessibility props to your component, this hook will add events for interoperability between actual elements and fake ones e.g. and
Argument | Type | Required? | Description |
---|---|---|---|
target | React.RefObject<T> | T | null | Yes | A React ref or HTML element |
options | UseTriggerOptions | No | Configuration options |
export interface UseTriggerOptions<E = React.MouseEvent<any, MouseEvent>> {
/**
* Adds this class name to props when the disclosure is open
*/
openClass?: string
/**
* Adds this class name to props when the disclosure is closed
*/
closedClass?: string
/**
* Adds this style to props when the disclosure is open
*/
openStyle?: React.CSSProperties
/**
* Adds this style to props when the disclosure is closed
*/
closedStyle?: React.CSSProperties
/**
* Adds an onClick handler in addition to the default one that
* toggles the disclosure's open state.
*/
onClick?: (e: E) => any
}
interface A11yProps<E extends React.MouseEvent<any, MouseEvent>> {
readonly 'aria-controls': string | undefined
readonly 'aria-expanded': string
readonly role: 'button'
readonly tabIndex: 0
readonly className: string | undefined
readonly style: React.CSSProperties | undefined
readonly onClick: (event: E) => void
}
import * as React from 'react'
import {useTrigger} from '@accessible/disclosure'
const MyTrigger = () => {
const ref = React.useRef(null)
const a11yProps = useTrigger(ref, {openClass: 'open', closedClass: 'closed'})
return (
<button ref={ref} {...a11yProps}>
Clicking me toggles the disclosure content
</button>
)
}
This component wraps any React element and adds an onClick
handler which toggles the open state
of the disclosure target.
Prop | Type | Default | Required? | Description |
---|---|---|---|---|
closedClass | string | undefined | No | This class name will be applied to the child element when the disclosure is closed . |
openClass | string | undefined | No | This class name will be applied to the child element when the disclosure is open . |
closedStyle | React.CSSProperties | undefined | No | These styles will be applied to the child element when the disclosure is closed . |
openStyle | React.CSSProperties | undefined | No | These styles name will be applied to the child element when the disclosure is open . |
children | React.ReactElement | undefined | Yes | The child is cloned by this component and has aria attributes injected into its props as well as the events defined above. |
<Trigger on='click'>
<button className='my-button'>Open me!</button>
</Trigger>
// <button
// class="my-button"
// aria-controls="🅰12"
// aria-expanded="false"
// >
// Open me!
// </button>
A React hook for creating a headless close button to WAI-ARIA authoring practices. In addition to providing accessibility props to your component, this hook will add events for interoperability between actual
Argument | Type | Required? | Description |
---|---|---|---|
target | React.RefObject<T> | T | null | Yes | A React ref or HTML element |
options | UseCloseButtonOptions | No | Configuration options |
export interface UseCloseButtonOptions<E = React.MouseEvent<any, MouseEvent>> {
/**
* Adds an onClick handler in addition to the default one that
* closes the disclosure.
*/
onClick?: (e: E) => any
}
interface A11yProps<E extends React.MouseEvent<any, MouseEvent>> {
readonly 'aria-controls': string | undefined
readonly 'aria-expanded': string
readonly 'aria-label': 'Close'
readonly role: 'button'
readonly tabIndex: 0
readonly onClick: (event: E) => void
}
import * as React from 'react'
import {useCloseButton} from '@accessible/disclosure'
const MyTrigger = () => {
const ref = React.useRef(null)
const a11yProps = useCloseButton(ref, {
onClick: () => console.log('Closing!'),
})
return (
<button ref={ref} {...a11yProps}>
Clicking me closes the disclosure content
</button>
)
}
This is a convenience component that wraps any React element and adds an onClick handler which closes the disclosure.
Prop | Type | Default | Required? | Description |
---|---|---|---|---|
children | React.ReactElement | undefined | Yes | The child is cloned by this component and has aria attributes injected into its props as well as the events defined above. |
<CloseButton>
<button className='my-button'>Close me</button>
</CloseButton>
// <button
// class="my-button"
// aria-controls="disclosure--12"
// aria-expanded="false"
// >
// Close me
// </button>
This hook provides the value of the disclosure's DisclosureContextValue object
export interface DisclosureContextValue {
/**
* The open state of the disclosure
*/
isOpen: boolean
/**
* Opens the disclosure
*/
open: () => void
/**
* Closes the disclosure
*/
close: () => void
/**
* Toggles the open state of the disclosure
*/
toggle: () => void
/**
* A unique ID for the disclosure target
*/
id?: string
}
const Component = () => {
const {open, close, toggle, isOpen} = useDisclosure()
return <button onClick={toggle}>Toggle the disclosure</button>
}
MIT
FAQs
🅰 An accessible and versatile disclosure component for React
The npm package @accessible/disclosure receives a total of 311 weekly downloads. As such, @accessible/disclosure popularity was classified as not popular.
We found that @accessible/disclosure 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
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.