Skip to content

Commit 6a68fb4

Browse files
committed
Merge branch '116' of https://github.com/AJIXuMuK/sp-dev-fx-controls-react into AJIXuMuK-116
2 parents 7cd4e76 + 5dc26f1 commit 6a68fb4

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

docs/documentation/docs/controls/fields/FieldNameRenderer.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ The FieldNameRenderer component can be configured with the following properties:
3737
| isLink | boolean | yes | True if the name should be rendered as a link. |
3838
| isNew | boolean | no | True if the document is new. |
3939
| filePath | string | no | Path to the document. |
40-
| hasPreview | boolean | no | True if the document has preview (true by default) |
41-
| onClick | (args: INameClickEventArgs) => {} | no | Custom handler for link click. If not set link click will lead to rendering document preview. |
42-
40+
| hasPreview | boolean | no | True if the document has preview and link href should be constructed to display the preview (instead of direct document's link). The flag works only if `onClick` property is NOT defined. |
41+
| onClick | (args: INameClickEventArgs) => {} | no | Custom handler for link click. If not set link click will lead to rendering document preview. Works if `isLink` is set to `true` |
42+
| onDoubleClick | (args: INameClickEventArgs) => {} | no | Custom handler for link double click. If not set link If not set link will use OOTB behavior. Works if `isLink` is set to `true` |
4343

4444
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/fields/FieldNameRenderer)
4545

src/controls/fields/fieldNameRenderer/FieldNameRenderer.tsx

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { override } from '@microsoft/decorators';
22
import * as React from 'react';
3+
import * as ReactDOM from 'react-dom';
4+
35
import { css } from 'office-ui-fabric-react/lib/Utilities';
46
import { Icon } from 'office-ui-fabric-react/lib/Icon';
57
import { Link } from 'office-ui-fabric-react/lib/Link';
@@ -28,13 +30,20 @@ export interface IFieldNameRendererProps extends IFieldRendererProps {
2830
*/
2931
isNew?: boolean;
3032
/**
31-
* true if the document type has preview (true by default)
33+
* true if the document type has preview (true by default).
34+
* The flag impacts on the link's href:
35+
* if the flag is tru then the href is constructed like #id=${filePath}&parent=${filePath.substring(0, filePath.lastIndexOf('/'))},
36+
* otherwise the href will contain filePath only.
3237
*/
3338
hasPreview?: boolean;
3439
/**
3540
* custom handler for link click. If not set link click will lead to rendering document preview
3641
*/
3742
onClick?: (args: IFieldNameClickEventArgs) => {};
43+
/**
44+
* custom handler for link double click. If not set link will use OOTB behavior.
45+
*/
46+
onDoubleClick?: (args: IFieldNameClickEventArgs) => {};
3847
}
3948

4049
/**
@@ -57,12 +66,37 @@ export interface IFieldNameClickEventArgs {
5766
* - Title
5867
*/
5968
export class FieldNameRenderer extends React.Component<IFieldNameRendererProps, IFieldNameRendererState> {
69+
private _button: HTMLButtonElement;
70+
6071
public constructor(props: IFieldNameRendererProps, state: IFieldNameRendererState) {
6172
super(props, state);
6273

6374
telemetry.track('FieldNameRenderer', {});
6475

6576
this.state = {};
77+
78+
this._onDoubleClick = this._onDoubleClick.bind(this);
79+
}
80+
81+
@override
82+
public componentDidMount() {
83+
//
84+
// small hack for double click.
85+
// unfortunately, we can't use React onDoubleClick because React doesn't guaranty the sequence of handlers.
86+
// And stopPropagation could not make effect.
87+
//
88+
if (this.props.onDoubleClick && this.props.isLink) {
89+
const domNode = ReactDOM.findDOMNode(this);
90+
this._button = domNode.querySelector('button');
91+
this._button.addEventListener('dblclick', this._onDoubleClick, false);
92+
}
93+
}
94+
95+
@override
96+
public componentWillUnmount() {
97+
if (this._button) {
98+
this._button.removeEventListener('dblclick', this._onDoubleClick);
99+
}
66100
}
67101

68102
@override
@@ -76,7 +110,10 @@ export class FieldNameRenderer extends React.Component<IFieldNameRendererProps,
76110

77111
if (isLink) {
78112
if (this.props.onClick) {
79-
value = <Link onClick={this._onClick.bind(this)} style={this.props.cssProps} className={styles.value}>{this.props.text}</Link>;
113+
value = <Link
114+
onClick={this._onClick.bind(this)}
115+
style={this.props.cssProps}
116+
className={styles.value}>{this.props.text}</Link>;
80117
}
81118
else {
82119
let url: string;
@@ -103,13 +140,23 @@ export class FieldNameRenderer extends React.Component<IFieldNameRendererProps,
103140
</span>;
104141
}
105142

106-
private _onClick(e): void {
143+
private _onClick(e): boolean {
107144
if (this.props.onClick) {
108145
e.stopPropagation();
109146
e.preventDefault();
110147
const args: IFieldNameClickEventArgs = this.props as IFieldNameClickEventArgs;
111148
this.props.onClick(args);
112-
return;
149+
return false;
150+
}
151+
}
152+
153+
private _onDoubleClick(e): boolean {
154+
if (this.props.onDoubleClick) {
155+
e.stopPropagation();
156+
e.preventDefault();
157+
const args: IFieldNameClickEventArgs = this.props as IFieldNameClickEventArgs;
158+
this.props.onDoubleClick(args);
159+
return false;
113160
}
114161
}
115162
}

0 commit comments

Comments
 (0)