You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/demo/src/content/components/format-date.mdx
+23-9Lines changed: 23 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,8 @@ The <code>FormatDate</code> component renders a date as either **relative** time
18
18
19
19
When showing relative time, a tooltip reveals the absolute time on hover or keyboard focus.
20
20
21
+
If no date is provided (`null`, `undefined`, or an empty string), the component renders a `---` placeholder instead.
22
+
21
23
## Time zones
22
24
23
25
Absolute time is formatted in **UTC by default**. To render in a different zone, pass a `timeZone` (e.g. `"America/New_York"`). Relative time reads the same everywhere.
@@ -108,14 +110,26 @@ For a short numeric date like `2026-06-09`, use numeric options. Digit _order_ i
108
110
/>
109
111
```
110
112
113
+
## Empty state
114
+
115
+
When `date` is missing — `null`, `undefined`, or an empty string — the component renders a `---` placeholder with an accessible "No date" label. This is distinct from passing a present-but-unparseable value (e.g. `"not-a-date"`), which renders `Invalid date`.
116
+
117
+
<FormatDatedate={null} />
118
+
119
+
```tsx
120
+
<FormatDatedate={null} />
121
+
<FormatDatedate={undefined} />
122
+
<FormatDatedate="" />
123
+
```
124
+
111
125
## Props
112
126
113
-
| Name | Description | Type | Default | Required |
/** The date to display. Accepts an ISO 8601 string, epoch milliseconds, or a Date. */
19
-
date: string|number|Date;
18
+
/** The date to display. Accepts an ISO 8601 string, epoch milliseconds, or a Date. A missing value (null, undefined, or empty string) renders a placeholder. */
0 commit comments