Skip to content

Commit 1fe6983

Browse files
authored
Clean up Modal and Popover props (#1090)
* Remove unused inner class name * Make modal style and className props consistent
1 parent c38d8ce commit 1fe6983

File tree

4 files changed

+44
-29
lines changed

4 files changed

+44
-29
lines changed

src/components/modal/Modal.js

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ function Modal({
1717
style,
1818
dialog_style,
1919
content_style,
20+
backdrop_style,
2021
class_name,
21-
modal_class_name,
22+
dialog_class_name,
2223
content_class_name,
2324
backdrop_class_name,
2425
autofocus,
@@ -31,10 +32,11 @@ function Modal({
3132
zIndex,
3233
dialogStyle,
3334
contentStyle,
35+
backdropStyle,
3436
className,
3537
backdropClassName,
3638
contentClassName,
37-
modalClassName,
39+
dialogClassName,
3840
setProps,
3941
...otherProps
4042
}) {
@@ -48,11 +50,12 @@ function Modal({
4850
<RBModal
4951
animation={fade}
5052
dialogAs={tag}
53+
className={class_name || className}
5154
dialogStyle={dialog_style || dialogStyle}
55+
dialogClassName={dialog_class_name || dialogClassName}
5256
contentStyle={content_style || contentStyle}
53-
dialogClassName={class_name || className}
54-
className={modal_class_name || modalClassName}
5557
contentClassName={content_class_name || contentClassName}
58+
backdropStyle={backdrop_style || backdropStyle}
5659
backdropClassName={backdrop_class_name || backdropClassName}
5760
autoFocus={autofocus || autoFocus}
5861
enforceFocus={enforceFocus}
@@ -145,23 +148,28 @@ Modal.propTypes = {
145148
*/
146149
content_style: PropTypes.object,
147150

151+
/**
152+
* Inline CSS styles to apply to the backdrop
153+
*/
154+
backdrop_style: PropTypes.object,
155+
148156
/**
149157
* Additional CSS classes to apply to the Modal.
150158
*/
151159
class_name: PropTypes.string,
152160

153161
/**
154-
* CSS class to apply to the modal.
162+
* Additional CSS classes to apply to the modal.
155163
*/
156-
modal_class_name: PropTypes.string,
164+
dialog_class_name: PropTypes.string,
157165

158166
/**
159-
* CSS class to apply to the backdrop.
167+
* Additional CSS classes to apply to the modal-backdrop.
160168
*/
161169
backdrop_class_name: PropTypes.string,
162170

163171
/**
164-
* CSS class to apply to the modal content.
172+
* Additional CSS classes to apply to the modal content.
165173
*/
166174
content_class_name: PropTypes.string,
167175

@@ -209,6 +217,13 @@ Modal.propTypes = {
209217
*/
210218
contentStyle: PropTypes.object,
211219

220+
/**
221+
* **DEPRECATED** Use `content_style` instead.
222+
*
223+
* Inline CSS styles to apply to the backdrop
224+
*/
225+
backdropStyle: PropTypes.object,
226+
212227
/**
213228
* **DEPRECATED** Use `class_name` instead.
214229
*
@@ -219,23 +234,23 @@ Modal.propTypes = {
219234
/**
220235
* **DEPRECATED** Use `backdrop_class_name` instead
221236
*
222-
* CSS class to apply to the backdrop.
237+
* Additional CSS classes to apply to the modal-backdrop.
223238
*/
224239
backdropClassName: PropTypes.string,
225240

226241
/**
227242
* **DEPRECATED** Use `content_class_name` instead
228243
*
229-
* CSS class to apply to the modal content.
244+
* Additional CSS classes to apply to the modal-content.
230245
*/
231246
contentClassName: PropTypes.string,
232247

233248
/**
234-
* **DEPRECATED** Use `modal_class_name` instead
249+
* **DEPRECATED** Use `dialog_class_name` instead
235250
*
236-
* CSS class to apply to the modal.
251+
* Additional CSS classes to apply to the modal-dialog.
237252
*/
238-
modalClassName: PropTypes.string,
253+
dialogClassName: PropTypes.string,
239254

240255
/**
241256
* **DEPRECATED** Use `autofocus` instead

src/components/modal/__tests__/Modal.test.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,14 @@ describe('Modal', () => {
8686
'custom-modal-backdrop'
8787
);
8888

89+
// Backdrop style
90+
rerender(<Modal is_open backdrop_style={{color: 'red'}} />);
91+
expect(document.body.querySelector('.modal-backdrop')).toHaveStyle({
92+
color: 'red'
93+
});
94+
8995
// Dialog class name
90-
rerender(<Modal is_open class_name="custom-modal-dialog" />);
96+
rerender(<Modal is_open dialog_class_name="custom-modal-dialog" />);
9197
expect(document.body.querySelector('.modal-dialog')).toHaveClass(
9298
'custom-modal-dialog'
9399
);
@@ -106,10 +112,14 @@ describe('Modal', () => {
106112
});
107113

108114
// Modal class name
109-
rerender(<Modal is_open modal_class_name="custom-modal-class" />);
115+
rerender(<Modal is_open class_name="custom-modal-class" />);
110116
expect(document.body.querySelector('.modal')).toHaveClass(
111117
'custom-modal-class'
112118
);
119+
120+
// Modal style
121+
rerender(<Modal is_open style={{color: 'red'}} />);
122+
expect(document.body.querySelector('.modal')).toHaveStyle({color: 'red'});
113123
});
114124

115125
test('sets z-index with zindex and zIndex', () => {

src/components/popover/Popover.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,6 @@ Popover.propTypes = {
193193
*/
194194
class_name: PropTypes.string,
195195

196-
/**
197-
* CSS class to apply to the Popover.
198-
*/
199-
inner_class_name: PropTypes.string,
200-
201196
/**
202197
* Used to allow user interactions to be persisted when the page is refreshed.
203198
* See https://dash.plotly.com/persistence for more details
@@ -238,13 +233,6 @@ Popover.propTypes = {
238233
*/
239234
className: PropTypes.string,
240235

241-
/**
242-
* **DEPRECATED** Use `inner_class_name` instead.
243-
*
244-
* CSS class to apply to the Popover.
245-
*/
246-
innerClassName: PropTypes.string,
247-
248236
/**
249237
* Dash-assigned callback that gets fired when the value changes.
250238
*/

src/private/Modal.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const Modal = React.forwardRef(function Modal(
3939
children,
4040
dialogStyle,
4141
contentStyle,
42+
backdropStyle,
4243
'data-bs-theme': dataBsTheme,
4344
'aria-labelledby': ariaLabelledby,
4445
'aria-describedby': ariaDescribedby,
@@ -219,7 +220,7 @@ const Modal = React.forwardRef(function Modal(
219220
backdropClassName,
220221
!animation && 'show'
221222
)}
222-
style={{zIndex}}
223+
style={{...backdropStyle, zIndex}}
223224
/>
224225
),
225226
[animation, backdropClassName, zIndex]
@@ -253,8 +254,8 @@ const Modal = React.forwardRef(function Modal(
253254
{...props}
254255
onMouseDown={handleDialogMouseDown}
255256
className={dialogClassName}
256-
contentClassName={contentClassName}
257257
style={dialogStyle}
258+
contentClassName={contentClassName}
258259
contentStyle={contentStyle}
259260
>
260261
{children}
@@ -299,6 +300,7 @@ Modal.propTypes = {
299300
style: PropTypes.object,
300301
dialogStyle: PropTypes.object,
301302
contentStyle: PropTypes.object,
303+
backdropStyle: PropTypes.object,
302304
zIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
303305
size: PropTypes.string,
304306
fullscreen: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),

0 commit comments

Comments
 (0)