Skip to content
This repository was archived by the owner on Sep 30, 2025. It is now read-only.

Commit 6474bde

Browse files
Joel Warringtonkyledurand
authored andcommitted
[Modal] Activator no longer wrapped in Box (#10086)
### WHY are these changes introduced? Fixes Shopify/polaris-internal#1049 Because `<Modal />` wraps the `activator` in a `<Box />`, it is not possible to style elements inline. The `<Box />` can be removed as it is only used for passing the ref along, which we can pass to the activator instead with `React.cloneElement`. ### WHAT is this pull request doing? <details> <summary>1. Modal activator is no longer wrapped in a Box</summary> BEFORE: ```jsx <div class="Polaris-Box"> <button class="Polaris-Button" type="button"> <span class="Polaris-Button__Content"> <span class="Polaris-Button__Text">Click Me</span> </span> </button> </div> ``` AFTER: ```jsx <button class="Polaris-Button" type="button"> <span class="Polaris-Button__Content"> <span class="Polaris-Button__Text">Click Me</span> </span> </button> ``` </details> 2. The `ref` is attached to the `activator` instead of the box which used to wrap the `activator`. ### 🎩 checklist - [X] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [X] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [X] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [X] Updated the component's `README.md` with documentation changes - [X] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide
1 parent 67273fd commit 6474bde

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

.changeset/fair-olives-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': minor
3+
---
4+
5+
[Modal] Activator no longer wrapped in Box

polaris-react/src/components/Modal/Modal.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useState, useCallback, useRef, useId} from 'react';
1+
import React, {useState, useCallback, useRef, useId, cloneElement} from 'react';
22
import {TransitionGroup} from 'react-transition-group';
33

44
import {focusFirstFocusableNode} from '../../utilities/focus';
@@ -95,7 +95,7 @@ export const Modal: React.FunctionComponent<ModalProps> & {
9595
const [closing, setClosing] = useState(false);
9696

9797
const headerId = useId();
98-
const activatorRef = useRef<HTMLDivElement>(null);
98+
const activatorRef = useRef<HTMLElement>(null);
9999

100100
const i18n = useI18n();
101101
const iframeTitle = i18n.translate('Polaris.Modal.iFrameTitle');
@@ -223,9 +223,9 @@ export const Modal: React.FunctionComponent<ModalProps> & {
223223
const animated = !instant;
224224

225225
const activatorMarkup =
226-
activator && !isRef(activator) ? (
227-
<Box ref={activatorRef}>{activator}</Box>
228-
) : null;
226+
activator && !isRef(activator)
227+
? cloneElement(activator, {ref: activatorRef})
228+
: null;
229229

230230
return (
231231
<WithinContentContext.Provider value>

0 commit comments

Comments
 (0)