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": "Pass SelectionZone props through DetailsList and add alternate data-selection-auto-selection attribute name",
"type": "minor"
}
],
"packageName": "office-ui-fabric-react",
"email": "tmichon@microsoft.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export class DetailsList extends BaseComponent<IDetailsListProps, IDetailsListSt
onColumnHeaderContextMenu,
selectionMode,
selectionPreservedOnEmptyClick,
selectionZoneProps,
ariaLabel,
ariaLabelForGrid,
rowElementEventMap,
Expand Down Expand Up @@ -392,6 +393,7 @@ export class DetailsList extends BaseComponent<IDetailsListProps, IDetailsListSt
onItemInvoked={ onItemInvoked }
onItemContextMenu={ onItemContextMenu }
enterModalOnTouch={ this.props.enterModalSelectionOnTouch }
{ ...(selectionZoneProps || {}) }
Copy link
Copy Markdown
Member

@JasonGore JasonGore May 18, 2018

Choose a reason for hiding this comment

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

Is {} needed? Spreading undefined object should be ok

Copy link
Copy Markdown
Member Author

@ThomasMichon ThomasMichon May 22, 2018

Choose a reason for hiding this comment

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

According to ES6, {} is needed because otherwise it would fail. TypeScript's implementation just doesn't fail, though.

Edit: clarified language.

>
{ groups ? (
<GroupedList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as React from 'react';
import { DetailsList } from './DetailsList';
import {
ISelection,
SelectionMode
SelectionMode,
ISelectionZoneProps
} from '../../utilities/selection/index';
import { IRenderFunction } from '../../Utilities';
import {
Expand Down Expand Up @@ -92,6 +93,11 @@ export interface IDetailsListProps extends React.Props<DetailsList>, IWithViewpo
**/
selectionPreservedOnEmptyClick?: boolean;

/**
* Addition props to pass through to the selection zone created by default.
*/
selectionZoneProps?: ISelectionZoneProps;

/** Controls how the columns are adjusted. */
layoutMode?: DetailsListLayoutMode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,15 @@ describe('SelectionZone', () => {
expect(_selection.isIndexSelected(1)).toEqual(false);
});

it('select an item when a button is clicked that has data-selection-select', () => {
it('selects an item when a button is clicked that has data-selection-select', () => {
ReactTestUtils.Simulate.mouseDown(_select1);
expect(_selection.isIndexSelected(1)).toEqual(true);
});

it('selects an item when a button is clicked that has data-selection-select', () => {
ReactTestUtils.Simulate.keyDown(_select1, { which: KeyCodes.enter });
expect(_selection.isIndexSelected(1)).toEqual(true);
});
});

function _simulateClick(el: Element, eventData?: ReactTestUtils.SyntheticEventData): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ export class SelectionZone extends BaseComponent<ISelectionZoneProps, {}> {
break;
} else if (this._hasAttribute(target, SELECTION_INVOKE_ATTRIBUTE_NAME)) {
break;
} else if ((target === itemRoot || this._hasAttribute(target, SELECTION_SELECT_ATTRIBUTE_NAME))
} else if (
(target === itemRoot || this._shouldAutoSelect(target))
&& !this._isShiftPressed && !this._isCtrlPressed) {
this._onInvokeMouseDown(ev, this._getItemIndex(itemRoot));
break;
Expand Down Expand Up @@ -376,6 +377,11 @@ export class SelectionZone extends BaseComponent<ISelectionZoneProps, {}> {
// For toggle elements, assuming they are rendered as buttons, they will generate a click event,
// so we can no-op for any keydowns in this case.
break;
} else if (this._shouldAutoSelect(target)) {
// If the event went to an element which should trigger auto-select, select it and then let
// the default behavior kick in.
this._onInvokeMouseDown(ev, index);
break;
} else if ((ev.which === KeyCodes.enter || ev.which === KeyCodes.space) &&
(target.tagName === 'BUTTON' || target.tagName === 'A' || target.tagName === 'INPUT')) {
return false;
Expand Down Expand Up @@ -441,7 +447,10 @@ export class SelectionZone extends BaseComponent<ISelectionZoneProps, {}> {
}

private _onInvokeClick(ev: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>, index: number): void {
const { selection, onItemInvoked } = this.props;
const {
selection,
onItemInvoked
} = this.props;

if (onItemInvoked) {
onItemInvoked(selection.getItems()[index], index, ev.nativeEvent);
Expand Down Expand Up @@ -540,6 +549,10 @@ export class SelectionZone extends BaseComponent<ISelectionZoneProps, {}> {
return Number(itemRoot.getAttribute(SELECTION_INDEX_ATTRIBUTE_NAME));
}

private _shouldAutoSelect(element: HTMLElement): boolean {
return this._hasAttribute(element, SELECTION_SELECT_ATTRIBUTE_NAME);
}

private _hasAttribute(element: HTMLElement, attributeName: string): boolean {
let isToggle = false;

Expand Down