Skip to content

Commit 69e5616

Browse files
committed
Merge branch 'hugoabernier-dev' into dev
2 parents d32fd65 + 5321560 commit 69e5616

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

package-lock.json

Lines changed: 21 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/controls/richText/RichText.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@
230230
}
231231

232232
.ql-active .ql-toolbar {
233-
display: block;
233+
display: inline-flex;
234234
position: absolute;
235235
top: -28px;
236236
opacity: 1;

src/controls/richText/RichText.tsx

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { Icon } from 'office-ui-fabric-react/lib/Icon';
1717
import { elementContains } from 'office-ui-fabric-react/lib/Utilities';
1818
import * as telemetry from '../../common/telemetry';
1919

20+
21+
const TOOLBARPADDING: number = 28;
2022
/**
2123
* Creates a rich text editing control that mimics the out-of-the-box
2224
* SharePoint Rich Text control.
@@ -26,10 +28,10 @@ import * as telemetry from '../../common/telemetry';
2628
* - Tables aren't supported yet. I'll gladly add table formatting support if users request it.
2729
*/
2830
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;
3335

3436
private ddStyleOpts = [{
3537
key: 0,
@@ -114,11 +116,12 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
114116
insertUrl: undefined,
115117
insertUrlText: undefined,
116118
selectedText: undefined,
117-
selectedUrl: undefined
119+
selectedUrl: undefined,
120+
wrapperTop: 0
118121
};
119122

120123
// Get a unique toolbar id
121-
this.toolbarId = "toolbar_" + Guid.newGuid().toString();
124+
this._toolbarId = "toolbar_" + Guid.newGuid().toString();
122125
}
123126

124127
/**
@@ -130,6 +133,14 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
130133
document.addEventListener('click', this.handleClickOutside);
131134
document.addEventListener('focus', this.handleClickOutside);
132135
}
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+
});
133144
}
134145

135146
/**
@@ -168,7 +179,7 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
168179
*/
169180
public getEditor = (): Quill => {
170181
try {
171-
return this.quillElem!.getEditor();
182+
return this._quillElem!.getEditor();
172183
} catch (error) {
173184
return undefined;
174185
}
@@ -385,7 +396,7 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
385396
// Get a unique id for the toolbar
386397
const modules = {
387398
toolbar: {
388-
container: "#" + this.toolbarId,
399+
container: "#" + this._toolbarId,
389400
handlers: [
390401
"link" // disable the link handler so we can add our own
391402
]
@@ -428,8 +439,8 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
428439
Quill.register(SizeClass, true);
429440

430441
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}}>
433444
{
434445
showStyles && (
435446
<Dropdown className={`${styles.headerDropDown} ${styles.toolbarDropDown}`}
@@ -706,8 +717,8 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
706717
formats: formats
707718
});
708719

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);
711722
}
712723
}
713724
} catch (error) {
@@ -761,7 +772,7 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
761772
* Keeps track of whether we clicked outside the element
762773
*/
763774
private handleClickOutside = (event) => {
764-
let outside: boolean = !elementContains(this.wrapperRef, event.target);
775+
let outside: boolean = !elementContains(this._wrapperRef, event.target);
765776

766777
// Did we click outside?
767778
if (outside) {
@@ -785,13 +796,13 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
785796
* Links to the quill reference
786797
*/
787798
private linkQuill = (e: any) => {
788-
this.quillElem = e;
799+
this._quillElem = e;
789800
}
790801

791802
/**
792803
* Links to the property pane element
793804
*/
794805
private linkPropertyPane = (e: any) => {
795-
this.propertyPaneRef = e;
806+
this._propertyPaneRef = e;
796807
}
797808
}

src/controls/richText/RichText.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,6 @@ export interface IRichTextState {
135135

136136
/** The text */
137137
text: string;
138+
139+
wrapperTop: number;
138140
}

0 commit comments

Comments
 (0)