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": "OverflowSet: Allow the OverflowSet to not be contained within a FocusZone",
"type": "minor"
}
],
"packageName": "office-ui-fabric-react",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import * as React from 'react';
import {
css,
BaseComponent,
createRef
createRef,
getNativeProps,
divProperties,
focusFirstChild
} from '../../Utilities';
import { mergeStyles } from '../../Styling';
import { IOverflowSet, IOverflowSetProps, IOverflowSetItemProps } from './OverflowSet.types';
Expand All @@ -14,6 +17,17 @@ const styles: any = stylesImport;
export class OverflowSet extends BaseComponent<IOverflowSetProps, {}> implements IOverflowSet {

private _focusZone = createRef<FocusZone>();
private _divContainer = createRef<HTMLDivElement>();

constructor(props: IOverflowSetProps) {
super(props);

if (props.doNotContainWithinFocusZone) {
this._warnMutuallyExclusive({
'doNotContainWithinFocusZone': 'focusZoneProps'
});
}
}

public render() {
const {
Expand All @@ -22,29 +36,54 @@ export class OverflowSet extends BaseComponent<IOverflowSetProps, {}> implements
className,
focusZoneProps,
vertical = false,
role = 'menubar'
role = 'menubar',
doNotContainWithinFocusZone
} = this.props;

let Tag;
let uniqueComponentProps;

if (doNotContainWithinFocusZone) {
Tag = 'div';
uniqueComponentProps = {
...getNativeProps(this.props, divProperties),
ref: this._divContainer
};
} else {
Tag = FocusZone;
uniqueComponentProps = {
...focusZoneProps,
componentRef: this._focusZone,
direction: vertical ? FocusZoneDirection.vertical : FocusZoneDirection.horizontal
};
}

return (
<FocusZone
{ ...focusZoneProps }
componentRef={ this._focusZone }
<Tag
{ ...uniqueComponentProps }
className={ mergeStyles(
'ms-OverflowSet',
styles.root,
vertical && styles.rootVertical,
className
) }
direction={ vertical ? FocusZoneDirection.vertical : FocusZoneDirection.horizontal }
role={ role }
>
{ items && this._onRenderItems(items) }
{ overflowItems && overflowItems.length > 0 && this._onRenderOverflowButtonWrapper(overflowItems) }
</FocusZone>
</Tag>
);
}

public focus() {
if (this.props.doNotContainWithinFocusZone) {
if (this._divContainer.value) {
focusFirstChild(this._divContainer.value);
}

return;
}

if (this._focusZone.value) {
this._focusZone.value.focus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,19 @@ export interface IOverflowSetProps extends React.Props<OverflowSet> {

/**
* Custom properties for OverflowSet's FocusZone.
* If doNotContainWithinFocusZone is set to true focusZoneProps will be ignored.
* Use one or the other
*/
focusZoneProps?: IFocusZoneProps;

/**
* If true do not contain the OverflowSet inside of a FocusZone,
* otherwise the OverflowSet will contain a FocusZone.
* If this is set to true focusZoneProps will be ignored.
* Use one or the other
*/
doNotContainWithinFocusZone?: boolean;

/**
* The role for the OverflowSet.
* @default 'menubar'
Expand Down