Skip to content

Commit 597e978

Browse files
authored
fix(modals): prevent useText evaluation until fully mounted (#2038)
1 parent 5072696 commit 597e978

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

packages/modals/src/elements/Drawer/Drawer.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,13 @@ const DrawerComponent = forwardRef<HTMLDivElement, IDrawerProps>(
144144
const labelValue = hasHeader ? modalProps['aria-labelledby'] : props['aria-label'];
145145

146146
const ariaProps = {
147-
[attribute]: useText(DrawerComponent, { [attribute]: labelValue }, attribute, defaultValue!)
147+
[attribute]: useText(
148+
DrawerComponent,
149+
{ [attribute]: labelValue },
150+
attribute,
151+
defaultValue!,
152+
modalRef.current !== null /* prevents `useText` evaluation until fully mounted */
153+
)
148154
};
149155

150156
if (!rootNode) {

packages/modals/src/elements/Modal.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,13 @@ export const ModalComponent = forwardRef<HTMLDivElement, IModalProps>(
160160
: modalProps['aria-label'];
161161

162162
const ariaProps = {
163-
[attribute]: useText(ModalComponent, { [attribute]: labelValue }, attribute, defaultValue!)
163+
[attribute]: useText(
164+
ModalComponent,
165+
{ [attribute]: labelValue },
166+
attribute,
167+
defaultValue!,
168+
modalRef.current !== null /* prevents `useText` evaluation until fully mounted */
169+
)
164170
};
165171

166172
if (!rootNode) {

packages/modals/src/elements/TooltipDialog/TooltipDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ const TooltipDialogComponent = React.forwardRef<HTMLDivElement, ITooltipDialogPr
133133
TooltipDialogComponent,
134134
{ [attribute]: labelValue },
135135
attribute,
136-
defaultValue!
136+
defaultValue!,
137+
modalRef.current !== null /* prevents `useText` evaluation until fully mounted */
137138
)
138139
};
139140

0 commit comments

Comments
 (0)