Skip to content

Commit bd3a66e

Browse files
committed
feat(Dialog): add rtl support
1 parent d20bfca commit bd3a66e

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/dialog/dialog.jsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default class Dialog extends Component {
1818
static propTypes = {
1919
prefix: PropTypes.string,
2020
pure: PropTypes.bool,
21+
rtl: PropTypes.bool,
2122
className: PropTypes.string,
2223
/**
2324
* 是否显示
@@ -282,7 +283,12 @@ export default class Dialog extends Component {
282283
}
283284

284285
renderInner(closeable) {
285-
const { prefix, className, title, children, footer, footerAlign, footerActions, onOk, onCancel, okProps, cancelProps, onClose, locale, visible } = this.props;
286+
const {
287+
prefix, className, title,
288+
children, footer, footerAlign,
289+
footerActions, onOk, onCancel,
290+
okProps, cancelProps, onClose,
291+
locale, visible, rtl } = this.props;
286292
const others = pickOthers(Object.keys(Dialog.propTypes), this.props);
287293

288294
return (
@@ -298,6 +304,7 @@ export default class Dialog extends Component {
298304
cancelProps={cancelProps}
299305
locale={locale}
300306
closeable={closeable}
307+
rtl={rtl}
301308
onClose={onClose.bind(this, 'closeClick')}
302309
{...others}>
303310
{children}
@@ -307,7 +314,10 @@ export default class Dialog extends Component {
307314

308315
render() {
309316
const {
310-
prefix, visible, hasMask, animation, autoFocus, closeable, onClose, afterClose, shouldUpdatePosition, align, overlayProps
317+
prefix, visible, hasMask,
318+
animation, autoFocus, closeable,
319+
onClose, afterClose, shouldUpdatePosition,
320+
align, overlayProps, rtl,
311321
} = this.props;
312322

313323
const useCSS = this.useCSSToPosition();
@@ -326,7 +336,8 @@ export default class Dialog extends Component {
326336
onRequestClose: onClose,
327337
needAdjust: false,
328338
disableScroll: true,
329-
ref: this.getOverlayRef
339+
ref: this.getOverlayRef,
340+
rtl,
330341
};
331342
if (!useCSS) {
332343
newOverlayProps.beforePosition = this.beforePosition;
@@ -339,7 +350,7 @@ export default class Dialog extends Component {
339350
return (
340351
<Overlay {...newOverlayProps}>
341352
{useCSS ?
342-
<div className={`${prefix}dialog-container`}>
353+
<div className={`${prefix}dialog-container`} dir={rtl ? "rtl" : undefined}>
343354
{inner}
344355
</div> :
345356
inner}

src/dialog/inner.jsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export default class Inner extends Component {
2626
closeable: PropTypes.bool,
2727
onClose: PropTypes.func,
2828
locale: PropTypes.object,
29-
role: PropTypes.string
29+
role: PropTypes.string,
30+
rtl: PropTypes.bool,
3031
};
3132

3233
static defaultProps = {
@@ -65,7 +66,7 @@ export default class Inner extends Component {
6566
}
6667

6768
renderFooter() {
68-
const { prefix, footer, footerAlign, footerActions, locale } = this.props;
69+
const { prefix, footer, footerAlign, footerActions, locale, rtl } = this.props;
6970

7071
if (footer === false) {
7172
return null;
@@ -115,7 +116,7 @@ export default class Inner extends Component {
115116
}
116117

117118
render() {
118-
const { prefix, className, closeable, title, role } = this.props;
119+
const { prefix, className, closeable, title, role, rtl } = this.props;
119120
const others = pickOthers(Object.keys(Inner.propTypes), this.props);
120121
const newClassName = cx({
121122
[`${prefix}dialog`]: true,
@@ -137,7 +138,7 @@ export default class Inner extends Component {
137138
}
138139

139140
return (
140-
<div {...ariaProps} className={newClassName} {...others}>
141+
<div {...ariaProps} className={newClassName} {...others} dir={rtl ? "rtl" : undefined}>
141142
{header}
142143
{body}
143144
{footer}

src/dialog/show.jsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Modal extends Component {
1919
static propTypes = {
2020
prefix: PropTypes.string,
2121
pure: PropTypes.bool,
22+
rtl: PropTypes.bool,
2223
type: PropTypes.string,
2324
title: PropTypes.node,
2425
content: PropTypes.node,
@@ -83,7 +84,12 @@ class Modal extends Component {
8384
}
8485

8586
render() {
86-
const { prefix, type, title, content, messageProps, footerActions, onOk, onCancel, onClose, okProps, needWrapper, ...others } = this.props;
87+
const {
88+
prefix, type, title,
89+
content, messageProps, footerActions,
90+
onOk, onCancel, onClose,
91+
okProps, needWrapper, rtl,
92+
...others } = this.props;
8793
const newTitle = needWrapper && type ? null : title;
8894

8995
const newContent = needWrapper && type ? (
@@ -95,6 +101,7 @@ class Modal extends Component {
95101
title={title}
96102
className={cx(`${prefix}dialog-message`, messageProps.className)}>
97103
{content}
104+
rtl={rtl}
98105
</Message>
99106
) : content;
100107

@@ -117,6 +124,7 @@ class Modal extends Component {
117124
{...others}
118125
visible={visible}
119126
title={newTitle}
127+
rtl={rtl}
120128
footerActions={newFooterActions}
121129
onOk={this.state.loading ? noop : newOnOk}
122130
onCancel={newOnCancel}

0 commit comments

Comments
 (0)