Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom KeyUp support to Group Header #15478

Merged
merged 11 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from 8 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
8 changes: 8 additions & 0 deletions change/office-ui-fabric-react-2020-10-12-13-11-10-7.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "minor",
"comment": "Add custom KeyUp support for Group Header",
"packageName": "office-ui-fabric-react",
"email": "bcoard@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-10-12T20:11:10.321Z"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4968,6 +4968,7 @@ export interface IGroupDividerProps {
isSelected?: boolean;
loadingText?: string;
onGroupHeaderClick?: (group: IGroup) => void;
onGroupHeaderKeyUp?: (ev: React.KeyboardEvent<HTMLElement>, group: IGroup) => void;
onRenderTitle?: IRenderFunction<IGroupHeaderProps>;
onToggleCollapse?: (group: IGroup) => void;
onToggleSelectGroup?: (group: IGroup) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,20 @@ export class GroupHeaderBase extends React.Component<IGroupHeaderProps, IGroupHe
};

private _onKeyUp = (ev: React.KeyboardEvent<HTMLElement>): void => {
const shouldOpen = this.state.isCollapsed && ev.which === getRTLSafeKeyCode(KeyCodes.right, this.props.theme);
const shouldClose = !this.state.isCollapsed && ev.which === getRTLSafeKeyCode(KeyCodes.left, this.props.theme);
if (shouldClose || shouldOpen) {
this._toggleCollapse();
ev.stopPropagation();
ev.preventDefault();
const { group, onGroupHeaderKeyUp } = this.props;

if (onGroupHeaderKeyUp) {
onGroupHeaderKeyUp(ev, group!);
}

if (!ev.defaultPrevented) {
const shouldOpen = this.state.isCollapsed && ev.which === getRTLSafeKeyCode(KeyCodes.right, this.props.theme);
const shouldClose = !this.state.isCollapsed && ev.which === getRTLSafeKeyCode(KeyCodes.left, this.props.theme);
if (shouldClose || shouldOpen) {
this._toggleCollapse();
ev.stopPropagation();
ev.preventDefault();
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ export interface IGroupDividerProps {
/** Callback for when the group header is clicked. */
onGroupHeaderClick?: (group: IGroup) => void;

/** Callback for when KeyUp on the group header is invoked. */
dzearing marked this conversation as resolved.
Show resolved Hide resolved
onGroupHeaderKeyUp?: (ev: React.KeyboardEvent<HTMLElement>, group: IGroup) => void;

/** Callback for when the group is expanded or collapsed. */
onToggleCollapse?: (group: IGroup) => void;

Expand Down