@@ -17,6 +17,8 @@ import { Icon } from 'office-ui-fabric-react/lib/Icon';
17
17
import { elementContains } from 'office-ui-fabric-react/lib/Utilities' ;
18
18
import * as telemetry from '../../common/telemetry' ;
19
19
20
+
21
+ const TOOLBARPADDING : number = 28 ;
20
22
/**
21
23
* Creates a rich text editing control that mimics the out-of-the-box
22
24
* SharePoint Rich Text control.
@@ -26,10 +28,10 @@ import * as telemetry from '../../common/telemetry';
26
28
* - Tables aren't supported yet. I'll gladly add table formatting support if users request it.
27
29
*/
28
30
export class RichText extends React . Component < IRichTextProps , IRichTextState > {
29
- private quillElem : ReactQuill = undefined ;
30
- private wrapperRef = undefined ;
31
- private propertyPaneRef : RichTextPropertyPane = undefined ;
32
- private toolbarId = undefined ;
31
+ private _quillElem : ReactQuill = undefined ;
32
+ private _wrapperRef : HTMLDivElement = undefined ;
33
+ private _propertyPaneRef : RichTextPropertyPane = undefined ;
34
+ private _toolbarId = undefined ;
33
35
34
36
private ddStyleOpts = [ {
35
37
key : 0 ,
@@ -114,11 +116,12 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
114
116
insertUrl : undefined ,
115
117
insertUrlText : undefined ,
116
118
selectedText : undefined ,
117
- selectedUrl : undefined
119
+ selectedUrl : undefined ,
120
+ wrapperTop : 0
118
121
} ;
119
122
120
123
// Get a unique toolbar id
121
- this . toolbarId = "toolbar_" + Guid . newGuid ( ) . toString ( ) ;
124
+ this . _toolbarId = "toolbar_" + Guid . newGuid ( ) . toString ( ) ;
122
125
}
123
126
124
127
/**
@@ -130,6 +133,14 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
130
133
document . addEventListener ( 'click' , this . handleClickOutside ) ;
131
134
document . addEventListener ( 'focus' , this . handleClickOutside ) ;
132
135
}
136
+
137
+ const clientRect : ClientRect = this . _wrapperRef . getBoundingClientRect ( ) ;
138
+ const parentClientRect : ClientRect = this . _wrapperRef . parentElement . getBoundingClientRect ( ) ;
139
+ const toolbarTop : number = clientRect . top - parentClientRect . top - TOOLBARPADDING ;
140
+
141
+ this . setState ( {
142
+ wrapperTop : toolbarTop
143
+ } ) ;
133
144
}
134
145
135
146
/**
@@ -168,7 +179,7 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
168
179
*/
169
180
public getEditor = ( ) : Quill => {
170
181
try {
171
- return this . quillElem ! . getEditor ( ) ;
182
+ return this . _quillElem ! . getEditor ( ) ;
172
183
} catch ( error ) {
173
184
return undefined ;
174
185
}
@@ -385,7 +396,7 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
385
396
// Get a unique id for the toolbar
386
397
const modules = {
387
398
toolbar : {
388
- container : "#" + this . toolbarId ,
399
+ container : "#" + this . _toolbarId ,
389
400
handlers : [
390
401
"link" // disable the link handler so we can add our own
391
402
]
@@ -428,8 +439,8 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
428
439
Quill . register ( SizeClass , true ) ;
429
440
430
441
return (
431
- < div ref = { ( ref ) => this . wrapperRef = ref } className = { `${ styles . richtext && this . state . editing ? 'ql-active' : undefined } ${ this . props . className } ` } >
432
- < div id = { this . toolbarId } >
442
+ < div ref = { ( ref ) => this . _wrapperRef = ref } className = { `${ styles . richtext && this . state . editing ? 'ql-active' : undefined } ${ this . props . className } ` } >
443
+ < div id = { this . _toolbarId } style = { { top : this . state . wrapperTop } } >
433
444
{
434
445
showStyles && (
435
446
< Dropdown className = { `${ styles . headerDropDown } ${ styles . toolbarDropDown } ` }
@@ -706,8 +717,8 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
706
717
formats : formats
707
718
} ) ;
708
719
709
- if ( this . propertyPaneRef && this . state . morePaneVisible ) {
710
- this . propertyPaneRef . onChangeSelection ( range , oldRange , source ) ;
720
+ if ( this . _propertyPaneRef && this . state . morePaneVisible ) {
721
+ this . _propertyPaneRef . onChangeSelection ( range , oldRange , source ) ;
711
722
}
712
723
}
713
724
} catch ( error ) {
@@ -761,7 +772,7 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
761
772
* Keeps track of whether we clicked outside the element
762
773
*/
763
774
private handleClickOutside = ( event ) => {
764
- let outside : boolean = ! elementContains ( this . wrapperRef , event . target ) ;
775
+ let outside : boolean = ! elementContains ( this . _wrapperRef , event . target ) ;
765
776
766
777
// Did we click outside?
767
778
if ( outside ) {
@@ -785,13 +796,13 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
785
796
* Links to the quill reference
786
797
*/
787
798
private linkQuill = ( e : any ) => {
788
- this . quillElem = e ;
799
+ this . _quillElem = e ;
789
800
}
790
801
791
802
/**
792
803
* Links to the property pane element
793
804
*/
794
805
private linkPropertyPane = ( e : any ) => {
795
- this . propertyPaneRef = e ;
806
+ this . _propertyPaneRef = e ;
796
807
}
797
808
}
0 commit comments