@@ -65,13 +65,40 @@ const isWindows = 'navigator' in global && /Win/i.test(navigator.platform);
65
65
const isMacLike =
66
66
'navigator' in global && / ( M a c | i P h o n e | i P o d | i P a d ) / i. test ( navigator . platform ) ;
67
67
68
- const className = 'npm__react-simple-code-editor__textarea ' ;
68
+ const container = 'npm__react-simple-code-editor__container ' ;
69
69
70
70
const cssText = /* CSS */ `
71
+ /**
72
+ * Make sure that layout related properties cannot be set on the children
73
+ * They will likely break the editor when set. The user can always use !important to force override.
74
+ */
75
+ .${ container } > pre * {
76
+ display: inline;
77
+ font-family: inherit;
78
+ font-size: inherit;
79
+ font-style: inherit;
80
+ font-variant-ligatures: inherit;
81
+ font-weight: inherit;
82
+ letter-spacing: inherit;
83
+ line-height: inherit;
84
+ margin-top: 0;
85
+ margin-right: 0;
86
+ margin-bottom: 0;
87
+ margin-left: 0;
88
+ padding-top: 0;
89
+ padding-right: 0;
90
+ padding-bottom: 0;
91
+ padding-left: 0;
92
+ border-top: 0;
93
+ border-right: 0;
94
+ border-bottom: 0;
95
+ border-left: 0;
96
+ }
97
+
71
98
/**
72
99
* Reset the text fill color so that placeholder is visible
73
100
*/
74
- .${ className } :empty {
101
+ .${ container } > textarea :empty {
75
102
-webkit-text-fill-color: inherit !important;
76
103
}
77
104
@@ -84,11 +111,11 @@ const cssText = /* CSS */ `
84
111
* So we use 'color: transparent' to make the text transparent on IE
85
112
* Unlike other browsers, it doesn't affect caret color in IE
86
113
*/
87
- .${ className } {
114
+ .${ container } > textarea {
88
115
color: transparent !important;
89
116
}
90
117
91
- .${ className } ::selection {
118
+ .${ container } > textarea ::selection {
92
119
background-color: #accef7 !important;
93
120
color: transparent !important;
94
121
}
@@ -498,6 +525,7 @@ export default class Editor extends React.Component<Props, State> {
498
525
const {
499
526
value,
500
527
style,
528
+ className,
501
529
padding,
502
530
highlight,
503
531
textareaId,
@@ -534,15 +562,18 @@ export default class Editor extends React.Component<Props, State> {
534
562
const highlighted = highlight ( value ) ;
535
563
536
564
return (
537
- < div { ...rest } style = { { ...styles . container , ...style } } >
565
+ < div
566
+ { ...rest }
567
+ style = { { ...styles . container , ...style } }
568
+ className = { `${ container } ${ className || '' } ` }
569
+ >
538
570
< textarea
539
571
ref = { c => ( this . _input = c ) }
540
572
style = { {
541
573
...styles . editor ,
542
574
...styles . textarea ,
543
575
...contentStyle ,
544
576
} }
545
- className = { className }
546
577
id = { textareaId }
547
578
value = { value }
548
579
onChange = { this . _handleChange }
@@ -606,8 +637,14 @@ const styles = {
606
637
pointerEvents : 'none' ,
607
638
} ,
608
639
editor : {
609
- margin : 0 ,
610
- border : 0 ,
640
+ marginTop : 0 ,
641
+ marginRight : 0 ,
642
+ marginBottom : 0 ,
643
+ marginLeft : 0 ,
644
+ borderTop : 0 ,
645
+ borderRight : 0 ,
646
+ borderBottom : 0 ,
647
+ borderLeft : 0 ,
611
648
background : 'none' ,
612
649
boxSizing : 'inherit' ,
613
650
display : 'inherit' ,
0 commit comments