Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "Callout: Add `preventDismissOnLostFocus` prop.",
"type": "minor"
}
],
"packageName": "office-ui-fabric-react",
"email": "jetao@microsoft.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ export interface ICalloutProps {
isBeakVisible?: boolean;

/**
* If true then the onClose will not not dismiss on scroll
* If true then the callout will not dismiss on scroll
* @default false
*/
preventDismissOnScroll?: boolean;

/**
* If true then the callout will not dismiss when it loses focus
* @default false
*/
preventDismissOnLostFocus?: boolean;

/**
* If true the position returned will have the menu element cover the target.
* If false then it will position next to the target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface ICalloutState {
@customizable('CalloutContent', ['theme'])
export class CalloutContentBase extends BaseComponent<ICalloutProps, ICalloutState> {
public static defaultProps = {
preventDismissOnLostFocus: false,
preventDismissOnScroll: false,
isBeakVisible: true,
beakWidth: 16,
Expand Down Expand Up @@ -234,13 +235,15 @@ export class CalloutContentBase extends BaseComponent<ICalloutProps, ICalloutSta
protected _dismissOnLostFocus(ev: Event) {
const target = ev.target as HTMLElement;
const clickedOutsideCallout = this._hostElement.current && !elementContains(this._hostElement.current, target);
const { preventDismissOnLostFocus } = this.props;

if (
(!this._target && clickedOutsideCallout) ||
!preventDismissOnLostFocus &&
((!this._target && clickedOutsideCallout) ||
(ev.target !== this._targetWindow &&
clickedOutsideCallout &&
((this._target as MouseEvent).stopPropagation ||
(!this._target || (target !== this._target && !elementContains(this._target as HTMLElement, target)))))
(!this._target || (target !== this._target && !elementContains(this._target as HTMLElement, target))))))
) {
this.dismiss(ev);
}
Expand Down