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": "BaseButton: Add onFocusCapture to the split button container to focus the container instead of doing it in the menu onClick",
"type": "patch"
}
],
"packageName": "office-ui-fabric-react",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,6 @@ export class BaseButton extends BaseComponent<IBaseButtonProps, IBaseButtonState
};

private _onToggleMenu = (shouldFocusOnContainer: boolean): void => {
if (this._splitButtonContainer.current) {
this._splitButtonContainer.current.focus();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the right fix? It looks like you added it in March to fix some specific issues: #4222

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like we talked offline, we're getting rid of this and instead we're using the onFocus capture event to ensure that focus is set to the SplitButton Container instead of us manually putting it there.


const currentMenuProps = this.state.menuProps;
let shouldFocusOnMount = true;
if (this.props.menuProps && this.props.menuProps.shouldFocusOnMount === false) {
Expand Down Expand Up @@ -523,6 +519,7 @@ export class BaseButton extends BaseComponent<IBaseButtonProps, IBaseButtonState
onClick={!disabled && !primaryDisabled ? this._onSplitButtonPrimaryClick : undefined}
tabIndex={!disabled || allowDisabledFocus ? 0 : undefined}
aria-roledescription={buttonProps['aria-roledescription']}
onFocusCapture={this._onSplitContainerFocusCapture}
>
<span style={{ display: 'flex' }}>
{this._onRenderContent(tag, buttonProps)}
Expand All @@ -535,6 +532,12 @@ export class BaseButton extends BaseComponent<IBaseButtonProps, IBaseButtonState
);
}

private _onSplitContainerFocusCapture = (ev: React.FocusEvent<HTMLDivElement>) => {
// We should never be able to focus the individual buttons in a split button. Focus
// should always remain on the container.
this._splitButtonContainer.current && this._splitButtonContainer.current.focus();
};

private _onSplitButtonPrimaryClick = (ev: React.MouseEvent<HTMLDivElement>) => {
if (this._isExpanded) {
this._dismissMenu();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ exports[`Component Examples renders Button.CommandBar.Example.tsx correctly 1`]
data-is-focusable={true}
data-ktp-target={undefined}
onClick={[Function]}
onFocusCapture={[Function]}
onKeyDown={[Function]}
onTouchStart={[Function]}
role="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ exports[`Component Examples renders Button.Split.Example.tsx correctly 1`] = `
data-is-focusable={true}
data-ktp-target={undefined}
onClick={[Function]}
onFocusCapture={[Function]}
onKeyDown={[Function]}
onTouchStart={[Function]}
role="button"
Expand Down Expand Up @@ -387,6 +388,7 @@ exports[`Component Examples renders Button.Split.Example.tsx correctly 1`] = `
data-is-focusable={true}
data-ktp-target={undefined}
onClick={[Function]}
onFocusCapture={[Function]}
onKeyDown={[Function]}
onTouchStart={[Function]}
role="button"
Expand Down Expand Up @@ -700,6 +702,7 @@ exports[`Component Examples renders Button.Split.Example.tsx correctly 1`] = `
data-is-focusable={true}
data-ktp-target={undefined}
onClick={undefined}
onFocusCapture={[Function]}
onKeyDown={[Function]}
onTouchStart={[Function]}
role="button"
Expand Down Expand Up @@ -1004,6 +1007,7 @@ exports[`Component Examples renders Button.Split.Example.tsx correctly 1`] = `
data-is-focusable={true}
data-ktp-target={undefined}
onClick={undefined}
onFocusCapture={[Function]}
onKeyDown={[Function]}
onTouchStart={[Function]}
role="button"
Expand Down Expand Up @@ -1317,6 +1321,7 @@ exports[`Component Examples renders Button.Split.Example.tsx correctly 2`] = `
data-is-focusable={true}
data-ktp-target={undefined}
onClick={[Function]}
onFocusCapture={[Function]}
onKeyDown={[Function]}
onTouchStart={[Function]}
role="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ exports[`Component Examples renders FocusZone.Tabbable.Example.tsx correctly 1`]
data-is-focusable={true}
data-ktp-target={undefined}
onClick={[Function]}
onFocusCapture={[Function]}
onKeyDown={[Function]}
onTouchStart={[Function]}
role="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ exports[`Component Examples renders Keytips.Button.Example.tsx correctly 1`] = `
data-is-focusable={true}
data-ktp-target="ktp-2-b"
onClick={[Function]}
onFocusCapture={[Function]}
onKeyDown={[Function]}
onTouchStart={[Function]}
role="button"
Expand Down