Repository navigation
ReadonlyInput
ReadonlyInput is a small display component for labeled, read-only values. It uses semantic description-list markup, supports optional skeleton loading, optional tooltip help text, and a numeric display variant for values that should use the number-specific style.
It is useful anywhere the UI needs to present field-style data without allowing user editing, such as profile details, search result summaries, or detail panels.
| Name | Type | Required | Description |
|---|---|---|---|
label |
string |
✅ | The label displayed above the content |
displayLabel |
boolean |
❌ | Whether to display the label. Defaults to true. |
labelClassName |
string |
❌ | Additional CSS class name to be applied to the label. Defaults to ''. |
children |
React.ReactNode |
❌ | The content to display. Falls back to -- when children is null or undefined
|
showSkeleton |
boolean |
❌ | If true, renders Carbon's TextInputSkeleton instead of the value content. Defaults to false. |
id |
string |
❌ | HTML id attribute for the component's root element |
tooltipText |
string |
❌ | Text shown in a Carbon DefinitionTooltip wrapped around the displayed content |
isNumber |
boolean |
❌ | If true, applies number-specific styling (monospace font) to the content |
import ReadonlyInput from "@/components/Form/ReadonlyInput";
<ReadonlyInput label="Email Address">user@example.com</ReadonlyInput>;<ReadonlyInput
label="Employee ID"
tooltipText="This is the unique identifier assigned by HR"
>
EMP-12345
</ReadonlyInput><ReadonlyInput label="Phone Number" isNumber={true}>
(555) 123-4567
</ReadonlyInput>const [loading, setLoading] = React.useState(true);
<ReadonlyInput label="User Name" showSkeleton={loading}>
John Doe
</ReadonlyInput>;<ReadonlyInput
id="user-details-name"
label="Full Name"
tooltipText="The user's legal full name"
isNumber={false}
showSkeleton={false}
>
Jane Smith
</ReadonlyInput>The component renders:
-
<dl>as the root container -
<dt>for the label -
<dd>for the displayed value
This keeps label-to-value relationships understandable to assistive technologies.
When showSkeleton is true, the component returns early and renders only a Carbon TextInputSkeleton. In that mode, it does not render the semantic description-list structure, tooltip wrapper, or value content.
If children is null or undefined, the component falls back to the PLACE_HOLDER constant, which is currently --.
Because the implementation uses the nullish coalescing operator, other falsy values are handled differently:
- empty string renders as the provided empty string value
- numeric values render normally
- boolean values are passed through React's normal rendering behavior
When tooltipText is provided, the rendered value is wrapped in Carbon's DefinitionTooltip with openOnHover enabled.
- string and number content are wrapped in a
<span>before being passed to the tooltip - existing React elements are rendered directly inside the tooltip wrapper
- no tooltip is rendered while
showSkeletonis enabled
displayLabel defaults to true. When it is set to false, the visible label text is hidden, but the <dt> element still renders and keeps its aria-label, so the semantic label remains available to assistive technologies.
The <dd> element gets a native title attribute only when children is a string and skeleton mode is off. The placeholder fallback does not automatically become the title value.
The component generates stable test ids from the label text using toKebabCase():
-
card-item-<label>for the root<dl> -
card-item-content-<label>for the<dd>
toKebabCase() trims the text, removes empty whitespace segments, lowercases the result, and joins words with hyphens.
Converts a text string into kebab-case format (words separated by hyphens, all lowercase).
Parameters:
-
text- The input string to convert
Returns: The kebab-case version of the input string
Examples:
toKebabCase("Hello World"); // => 'hello-world'
toKebabCase("Employee ID"); // => 'employee-id'
toKebabCase(" First Name "); // => 'first-name'
toKebabCase("This Is A Test"); // => 'this-is-a-test'Features:
- Trims leading and trailing whitespace
- Filters out empty words
- Converts to lowercase
- Joins words with hyphens
The default placeholder value displayed when no children are provided to the component.
Value: "--"
Usage:
import { PLACE_HOLDER } from "@/components/Form/ReadonlyInput/constants";
// The component automatically uses this when children is undefinedThe component applies the following CSS classes:
-
.card-item- Applied to the root<dl>element -
.card-item-label- Applied to the<dt>element -
.card-item-content- Applied to the<dd>element (default) -
.card-item-content-number- Applied to the<dd>element whenisNumber={true}
For custom styling, refer to index.scss in the component directory.
The component includes unit tests covering:
- Content rendering and placeholder behavior
- Skeleton loading states
- CSS class application
- Tooltip functionality
- Test ID generation
- Label visibility and
aria-labelpreservation - Edge cases such as empty strings, numbers, and booleans
Run tests with: npm run test:unit
- AutoCompleteInput - For searchable dropdowns
- ActiveMultiSelect - For multi-select inputs
- SearchInput - For search fields
This wiki documents NR Waste Plus for users and developers. Verify security and deployment guidance against the current application configuration before applying it elsewhere.
- Report an issue or ask a question in the GitHub repository.
- Follow the Contributing Guidelines to propose an update.
- Read the Code of Conduct.
Collection indexes support human browsing and machine retrieval. Keep both current when adding or moving wiki pages.
NR Waste Plus Wiki | GitHub Repository