diff --git a/src/components/CloseableContext.ts b/src/components/CloseableContext.ts
index c161d55d..9dcb7d76 100644
--- a/src/components/CloseableContext.ts
+++ b/src/components/CloseableContext.ts
@@ -1,10 +1,13 @@
import { createContext } from 'preact';
-/**
- * Provide a close handler to descendants. This can allow, e.g., button-like
- * components to correctly close a parent dialog or panel.
- */
export type CloseableInfo = {
+ /** The close button title. Defaults to "Close" */
+ title?: string;
+
+ /**
+ * Provide a close handler to descendants. This can allow, e.g., button-like
+ * components to correctly close a parent dialog or panel.
+ */
onClose: (() => void) | undefined;
};
diff --git a/src/components/feedback/Dialog.tsx b/src/components/feedback/Dialog.tsx
index 0744c2d7..ffa1412f 100644
--- a/src/components/feedback/Dialog.tsx
+++ b/src/components/feedback/Dialog.tsx
@@ -33,6 +33,9 @@ type ComponentProps = {
*/
onClose?: () => void;
+ /** Accessible title for the close button */
+ closeTitle?: string;
+
/**
* Element that should take focus when the Dialog is first rendered. When not
* provided ("auto"), the dialog's outer element will take focus. Setting this
@@ -89,6 +92,7 @@ export default function Dialog({
classes,
elementRef,
onClose,
+ closeTitle,
...rest
}: DialogProps) {
@@ -227,6 +231,7 @@ export default function Dialog({
// Provide a close handler to descendant components
const closeableContext: CloseableInfo = {
onClose: onClose ? closeHandler : undefined,
+ title: closeTitle,
};
return (
diff --git a/src/components/input/CloseButton.tsx b/src/components/input/CloseButton.tsx
index 81edd47f..52c497f5 100644
--- a/src/components/input/CloseButton.tsx
+++ b/src/components/input/CloseButton.tsx
@@ -22,14 +22,14 @@ export default function CloseButton({
classes,
elementRef,
- title = 'Close',
-
+ title,
onClick,
...iconButtonProps
}: CloseButtonProps) {
const closeableContext = useContext(CloseableContext);
- // Any provided `onClick` is prioritized, but also check to see if there is a
- // close handler provided by a `CloseableContext`
+ // Provided `title` and `onClick` are prioritized, but fall back to values
+ // from the `CloseableContext`
+ const buttonTitle = title ?? closeableContext?.title ?? 'Close';
const closeHandler = onClick ?? closeableContext?.onClose;
return (
@@ -37,7 +37,7 @@ export default function CloseButton({
data-component="CloseButton"
elementRef={downcastRef(elementRef)}
icon={CancelIcon}
- title={title}
+ title={buttonTitle}
classes={classes}
{...iconButtonProps}
onClick={closeHandler}
diff --git a/src/pattern-library/components/patterns/feedback/DialogPage.tsx b/src/pattern-library/components/patterns/feedback/DialogPage.tsx
index acf93d12..05b9bf99 100644
--- a/src/pattern-library/components/patterns/feedback/DialogPage.tsx
+++ b/src/pattern-library/components/patterns/feedback/DialogPage.tsx
@@ -225,7 +225,6 @@ export default function DialogPage() {
buttons={
@@ -256,11 +255,7 @@ export default function DialogPage() { used.
This dialog will close if you click outside of it
@@ -354,7 +348,7 @@ export default function DialogPage() { title="Dialog with close-on-Escape behavior" withSource > -This dialog will close if you press Escape.
@@ -380,11 +374,7 @@ export default function DialogPage() { title="Dialog that closes on external focus events" withSource > -This dialog will close if you focus outside of it
onClose
has also been provided.
+ string
+ {`'Close'`}
+ + This dialog has a custom title on the close button. Hover over + it to see it. +
+
This dialog will restore focus to the previously-focused
element on close.
@@ -553,7 +561,6 @@ export default function DialogPage() {
buttons={
This is a basic ModalDialog.
@@ -584,7 +591,6 @@ export default function DialogPage() {
This ModalDialog has a height of 25rem
.
@@ -700,7 +704,6 @@ export default function DialogPage() {
title="ModalDialog with a fixed height"
buttons={
This ModalDialog has a height of 25rem
and long
@@ -717,7 +720,6 @@ export default function DialogPage() {
@@ -735,7 +737,6 @@ export default function DialogPage() {
@@ -851,7 +852,6 @@ export default function DialogPage() {