Skip to content

Commit e0c93cc

Browse files
Merge branch 'master' of github.com:salesforce/design-system-react
2 parents 17cf0f9 + ec0ea25 commit e0c93cc

File tree

3 files changed

+89
-32
lines changed

3 files changed

+89
-32
lines changed

components/data-table/__examples__/advanced.jsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import createReactClass from 'create-react-class';
3+
import Dropdown from '~/components/menu-dropdown';
34
import DataTable from '~/components/data-table'; // `~` is replaced with design-system-react at runtime
45
import DataTableColumn from '~/components/data-table/column';
56
import DataTableCell from '~/components/data-table/cell';
@@ -174,8 +175,34 @@ const Example = createReactClass({
174175
label: 'Publish',
175176
value: '2',
176177
},
178+
{
179+
id: 2,
180+
label: 'Third of Seven',
181+
value: '3',
182+
},
183+
{
184+
id: 3,
185+
label: 'Fourth of Seven',
186+
value: '4',
187+
},
188+
{
189+
id: 4,
190+
label: 'Fifth of Seven',
191+
value: '5',
192+
},
193+
{
194+
id: 5,
195+
label: 'Sixth of Seven',
196+
value: '6',
197+
},
198+
{
199+
id: 6,
200+
label: 'Seventh of Seven',
201+
value: '7',
202+
},
177203
]}
178204
onAction={this.handleRowAction}
205+
dropdown={<Dropdown length="7" />}
179206
/>
180207
</DataTable>
181208
</IconSettings>

components/data-table/__tests__/data-table.browser-test.jsx

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import TestUtils from 'react-addons-test-utils';
44

55
import chai from 'chai';
66

7+
import Dropdown from '../../menu-dropdown';
78
import DataTable from '../../data-table';
89
import DataTableColumn from '../../data-table/column';
910
import DataTableRowActions from '../../data-table/row-actions';
@@ -328,25 +329,29 @@ describe('DataTable: ', function () {
328329
describe('w/ RowActions', function () {
329330
afterEach(removeTable);
330331

331-
it('renders the RowActions', function () {
332+
it('renders the RowActions and uses dropdown override property', function () {
332333
renderTable(
333334
<DataTable {...defaultProps}>
334335
{columns.map((columnProps) => (
335336
<DataTableColumn {...columnProps} key={columnProps.property} />
336337
))}
337338
<DataTableRowActions
338-
options={[
339-
{
340-
id: 0,
341-
label: 'Add to Group',
342-
value: '1',
343-
},
344-
{
345-
id: 1,
346-
label: 'Publish',
347-
value: '2',
348-
},
349-
]}
339+
dropdown={
340+
<Dropdown
341+
options={[
342+
{
343+
id: 0,
344+
label: 'Add to Group',
345+
value: '1',
346+
},
347+
{
348+
id: 1,
349+
label: 'Publish',
350+
value: '2',
351+
},
352+
]}
353+
/>
354+
}
350355
/>
351356
</DataTable>
352357
).call(this);
@@ -358,11 +363,18 @@ describe('DataTable: ', function () {
358363
rowActionMenus.should.have.length(6);
359364
});
360365

361-
it('calls onAction when an action is clicked', function (done) {
366+
it('calls onAction & onSelect when an action is clicked', function (done) {
367+
let expectedCalbacks = 2;
368+
362369
this.onAction = (item, action) => {
363370
item.id.should.equal('8IKZHZZV80');
364371
action.value.should.equal('1');
365-
done();
372+
if (!--expectedCalbacks) done();
373+
};
374+
375+
this.onSelect = (action) => {
376+
action.value.should.equal('1');
377+
if (!--expectedCalbacks) done();
366378
};
367379

368380
renderTable(
@@ -371,6 +383,7 @@ describe('DataTable: ', function () {
371383
<DataTableColumn {...columnProps} key={columnProps.property} />
372384
))}
373385
<DataTableRowActions
386+
onAction={this.onAction}
374387
options={[
375388
{
376389
id: 0,
@@ -383,7 +396,7 @@ describe('DataTable: ', function () {
383396
value: '2',
384397
},
385398
]}
386-
onAction={this.onAction}
399+
dropdown={<Dropdown onSelect={this.onSelect} />}
387400
/>
388401
</DataTable>
389402
).call(this);

components/data-table/row-actions.jsx

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,19 @@ const DataTableRowActions = createReactClass({
5757
/**
5858
* `Dropdown` options. See `Dropdown`.
5959
*/
60-
options: PropTypes.array.isRequired,
60+
options: PropTypes.array,
61+
/**
62+
* A [Dropdown](http://react.lightningdesignsystem.com/components/dropdown-menus/) component. The props from this drop will be merged and override any default props.
63+
* **Note:** onAction will not be overridden, both `DropDown`'s onSelect(dropDownActionOption) and onAction(rowItem, dropdownActionOption) will be called with appropriate parameters
64+
*/
65+
dropdown: PropTypes.node,
6166
},
6267

6368
getDefaultProps () {
6469
return {
6570
assistiveText: 'Actions',
6671
noHint: false,
72+
options: [],
6773
};
6874
},
6975

@@ -75,11 +81,36 @@ const DataTableRowActions = createReactClass({
7581
if (isFunction(this.props.onAction)) {
7682
this.props.onAction(this.props.item, selection);
7783
}
84+
if (this.props.dropdown && isFunction(this.props.dropdown.props.onSelect)) {
85+
this.props.dropdown.props.onSelect(selection);
86+
}
7887
},
7988

8089
// ### Render
8190
render () {
8291
// i18n
92+
const defaultDropdownProps = {
93+
align: 'right',
94+
buttonClassName: 'slds-button--icon-x-small',
95+
buttonVariant: 'icon',
96+
iconCategory: 'utility',
97+
iconName: 'down',
98+
iconSize: 'small',
99+
iconVariant: 'border-filled',
100+
assistiveText: this.props.assistiveText,
101+
className: this.props.className,
102+
options: this.props.options,
103+
hint: !this.props.noHint,
104+
id: this.props.id,
105+
};
106+
107+
const props = this.props.dropdown ? this.props.dropdown.props : {};
108+
const dropdownProps = {
109+
...defaultDropdownProps,
110+
...props,
111+
onSelect: this.handleSelect,
112+
};
113+
83114
return (
84115
/* eslint-disable jsx-a11y/no-static-element-interactions */
85116
<td
@@ -89,21 +120,7 @@ const DataTableRowActions = createReactClass({
89120
style={{ width: '3.25rem' }}
90121
>
91122
{/* eslint-enable jsx-a11y/no-static-element-interactions */}
92-
<Dropdown
93-
align="right"
94-
assistiveText={this.props.assistiveText}
95-
buttonClassName="slds-button--icon-x-small"
96-
buttonVariant="icon"
97-
className={this.props.className}
98-
options={this.props.options}
99-
hint={!this.props.noHint}
100-
iconCategory="utility"
101-
iconName="down"
102-
iconSize="small"
103-
iconVariant="border-filled"
104-
id={this.props.id}
105-
onSelect={this.handleSelect}
106-
/>
123+
<Dropdown {...dropdownProps} />
107124
</td>
108125
);
109126
},

0 commit comments

Comments
 (0)