Skip to content
Closed
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 @@ -92,11 +92,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 @@ -58,6 +58,7 @@ export interface ICalloutState {
export class CalloutContentBase extends BaseComponent<ICalloutProps, ICalloutState> {

public static defaultProps = {
preventDismissOnLostFocus: false,
preventDismissOnScroll: false,
isBeakVisible: true,
beakWidth: 16,
Expand Down Expand Up @@ -253,13 +254,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 &&
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely shouldn't be here. Instead don't add the focus listener.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can fix that. I was following the pattern of preventDismissOnScroll. Should I give it the same treatment?

Also this is a backfix from #5092 , I can make a follow-up PR on master to do the same thing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking into how the listeners are registered, is it correct to not register them based on preventDismissOnLostFocus? If _addListeners has already been called, according to the semantics of _hasListeners, it will not be called again. We could enter a situation where you create the Callout with preventDismissOnLostFocus={true}, later update it to false, but the handlers will not be registered.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm. Yeah that's true. For now you're probably right. In the long term it should be streamlined in some way, or perhaps each type of dismiss should have it's own handler. So there would be onFocusDismiss and onScrollDismiss so the user could choose to pass or not pass those dismiss events through. But that should probably be for 7.0

For now keep things the way they are.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joschect do you approve this PR then? or are there changes needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OWA has actually upgraded to Fabric 6 in the meantime, so unless we feel this API would be useful for any other Fabric 5 users, I can abandon this PR.

((!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