Skip to Content
🎉 Coral x Panda has been released 🎉 Read the Migration Guide

Visibility

The Visibility component is used to conceal elements visually while still keeping them accessible in the DOM. This is just like .sr-only, but as a React component.

Basic Usage

import { Visibility } from '@krakentech/coral'; <Visibility>Children visible by default</Visibility>

Properties

hidden

When the hidden prop is set to true, the child elements will be visually hidden while remaining accessible in the DOM.

<Visibility hidden={true}>Children hidden visually</Visibility>

display

We expose the display prop, to enable functionality such as hiding responsively with display: none.

<Visibility display="none">Children not displayed</Visibility>

Responsiveness

<Visibility hidden={{ md: true }}> Children hidden visually at the md breakpoint </Visibility>

Children hidden visually at the md breakpoint

Another example that is hidden by default and will be not hidden anymore starting at the md breakpoint.

<Visibility hidden={{ base: true, md: false }}> Children hidden visually by default and visible again at the md breakpoint </Visibility>

Children hidden visually by default and visible again at the md breakpoint

Full API

NameTypeDefault
attributesAttributes

This prop can be used to pass HTML attributes directly to the component. We currently allow passing data-* and aria-* attributes and the id. However, you can pass anything else with a type hack if necessary since this object is despread in to the component, without filtering its content.

Example usage:

AttributesProps: { 'id': 'close-button', 'aria-label': 'Close button', 'data-testid': 'close-button' };
component"symbol" | "object" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "big" | "blockquote" | "br" | "button" | "canvas" | "caption" | ... 154 more ... | ComponentType<...>

Overrides the element type that is rendered.

div
hiddenResponsiveVariant<boolean>

Should this component be hidden visually?

false
displayResponsiveVariant<ConditionalValue<WithEscapeHatch<OnlyKnown<"display", `var(--${string})` | Display | readonly string[] | undefined>>> | undefined>

The CSS display property to apply.

fullWidthboolean

If true, the element will take the full width of its parent.

false
childrenReactNode
Last updated on