-
Notifications
You must be signed in to change notification settings - Fork 434
add support for disabling data table selection (checkbox/radio) #3126
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
Changes from 3 commits
f954f06
f5ca033
82bb7ef
ccff4d2
ebfd8b0
ff60cb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,39 @@ const CustomDataTableCell = ({ children, ...props }) => ( | |
); | ||
CustomDataTableCell.displayName = DataTableCell.displayName; | ||
|
||
const items = [ | ||
{ | ||
id: '8IKZHZZV80', | ||
opportunityName: 'Acme - 1,200 Widgets', | ||
accountName: 'Acme', | ||
closeDate: '4/10/15', | ||
stage: 'Value Proposition', | ||
confidence: '70%', | ||
amount: '$25,000,000', | ||
contact: '[email protected]', | ||
}, | ||
{ | ||
id: '5GJOOOPWU7', | ||
opportunityName: 'Acme - 200 Widgets', | ||
accountName: 'Acme', | ||
closeDate: '1/31/15', | ||
stage: 'Prospecting', | ||
confidence: '30%', | ||
amount: '$5,000,000', | ||
contact: '[email protected]', | ||
}, | ||
{ | ||
id: '8IKZHZZV81', | ||
opportunityName: 'salesforce.com - 1,000 Widgets', | ||
accountName: 'salesforce.com', | ||
closeDate: '1/31/15 3:45PM', | ||
stage: 'Id. Decision Makers', | ||
confidence: '60%', | ||
amount: '$25,000', | ||
contact: '[email protected]', | ||
}, | ||
]; | ||
|
||
class Example extends React.Component { | ||
static displayName = 'DataTableExample'; | ||
|
||
|
@@ -23,43 +56,16 @@ class Example extends React.Component { | |
sortColumnDirection: { | ||
opportunityName: 'asc', | ||
}, | ||
items: [ | ||
{ | ||
id: '8IKZHZZV80', | ||
opportunityName: 'Acme - 1,200 Widgets', | ||
accountName: 'Acme', | ||
closeDate: '4/10/15', | ||
stage: 'Value Proposition', | ||
confidence: '70%', | ||
amount: '$25,000,000', | ||
contact: '[email protected]', | ||
}, | ||
{ | ||
id: '5GJOOOPWU7', | ||
opportunityName: 'Acme - 200 Widgets', | ||
accountName: 'Acme', | ||
closeDate: '1/31/15', | ||
stage: 'Prospecting', | ||
confidence: '30%', | ||
amount: '$5,000,000', | ||
contact: '[email protected]', | ||
}, | ||
{ | ||
id: '8IKZHZZV81', | ||
opportunityName: 'salesforce.com - 1,000 Widgets', | ||
accountName: 'salesforce.com', | ||
closeDate: '1/31/15 3:45PM', | ||
stage: 'Id. Decision Makers', | ||
confidence: '60%', | ||
amount: '$25,000', | ||
contact: '[email protected]', | ||
}, | ||
], | ||
items, | ||
selection: [], | ||
disabledSelection: [items[0]], | ||
}; | ||
|
||
handleChanged = (event, data) => { | ||
this.setState({ selection: data.selection }); | ||
const selections = data.selection.filter( | ||
(s) => !this.state.disabledSelection.includes(s) | ||
); | ||
this.setState({ selection: selections }); | ||
console.log('event: ', event, ', data: ', data); | ||
}; | ||
|
||
|
@@ -124,7 +130,8 @@ class Example extends React.Component { | |
onRowChange={this.handleChanged} | ||
onSort={this.handleSort} | ||
selection={this.state.selection} | ||
selectRows="radio" | ||
disabledSelection={this.state.disabledSelection} | ||
selectRows="checkbox" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the single select example for consumers. Please keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reverted the changes. I added a disabled checkbox in fixed-header example, which is already showing checkbox |
||
> | ||
<DataTableColumn | ||
isSorted={this.state.sortColumn === 'opportunityName'} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,39 @@ const CustomDataTableCell = ({ children, ...props }) => ( | |
); | ||
CustomDataTableCell.displayName = DataTableCell.displayName; | ||
|
||
const items = [ | ||
{ | ||
id: '8IKZHZZV80', | ||
opportunityName: 'Acme - 1,200 Widgets', | ||
accountName: 'Acme', | ||
closeDate: '4/10/15', | ||
stage: 'Value Proposition', | ||
confidence: '70%', | ||
amount: '$25,000,000', | ||
contact: '[email protected]', | ||
}, | ||
{ | ||
id: '5GJOOOPWU7', | ||
opportunityName: 'Acme - 200 Widgets', | ||
accountName: 'Acme', | ||
closeDate: '1/31/15', | ||
stage: 'Prospecting', | ||
confidence: '30%', | ||
amount: '$5,000,000', | ||
contact: '[email protected]', | ||
}, | ||
{ | ||
id: '8IKZHZZV81', | ||
opportunityName: 'salesforce.com - 1,000 Widgets', | ||
accountName: 'salesforce.com', | ||
closeDate: '1/31/15 3:45PM', | ||
stage: 'Id. Decision Makers', | ||
confidence: '60%', | ||
amount: '$25,000', | ||
contact: '[email protected]', | ||
}, | ||
]; | ||
|
||
class Example extends React.Component { | ||
static displayName = 'DataTableExample'; | ||
|
||
|
@@ -23,39 +56,9 @@ class Example extends React.Component { | |
sortColumnDirection: { | ||
opportunityName: 'asc', | ||
}, | ||
items: [ | ||
{ | ||
id: '8IKZHZZV80', | ||
opportunityName: 'Acme - 1,200 Widgets', | ||
accountName: 'Acme', | ||
closeDate: '4/10/15', | ||
stage: 'Value Proposition', | ||
confidence: '70%', | ||
amount: '$25,000,000', | ||
contact: '[email protected]', | ||
}, | ||
{ | ||
id: '5GJOOOPWU7', | ||
opportunityName: 'Acme - 200 Widgets', | ||
accountName: 'Acme', | ||
closeDate: '1/31/15', | ||
stage: 'Prospecting', | ||
confidence: '30%', | ||
amount: '$5,000,000', | ||
contact: '[email protected]', | ||
}, | ||
{ | ||
id: '8IKZHZZV81', | ||
opportunityName: 'salesforce.com - 1,000 Widgets', | ||
accountName: 'salesforce.com', | ||
closeDate: '1/31/15 3:45PM', | ||
stage: 'Id. Decision Makers', | ||
confidence: '60%', | ||
amount: '$25,000', | ||
contact: '[email protected]', | ||
}, | ||
], | ||
items, | ||
selection: [], | ||
disabledSelection: [items[0]], | ||
}; | ||
|
||
handleChanged = (event, data) => { | ||
|
@@ -123,6 +126,7 @@ class Example extends React.Component { | |
onRowChange={this.handleChanged} | ||
onSort={this.handleSort} | ||
selection={this.state.selection} | ||
disabledSelection={this.state.disabledSelection} | ||
selectRows="radio" | ||
> | ||
<DataTableColumn | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,6 +248,26 @@ describe('DataTable: ', function describeFunction() { | |
checkedBoxes.should.have.length(1); | ||
}); | ||
|
||
it('can start with a row disabled', function () { | ||
renderTable( | ||
<DataTable | ||
{...defaultProps} | ||
selection={[]} | ||
disabledSelection={defaultSelection} | ||
> | ||
{columns.map((columnProps) => ( | ||
<DataTableColumn {...columnProps} key={columnProps.property} /> | ||
))} | ||
</DataTable> | ||
).call(this); | ||
|
||
const tbody = getTable(this.dom).querySelectorAll('tbody')[0]; | ||
const disabledRows = tbody.querySelectorAll( | ||
'.slds-checkbox input:disabled' | ||
); | ||
disabledRows.should.have.length(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should spy the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated test |
||
}); | ||
|
||
it('can deselect a row', function (done) { | ||
this.onRowChange = (event, { selection }) => { | ||
selection.should.have.length(0); | ||
|
@@ -421,6 +441,25 @@ describe('DataTable: ', function describeFunction() { | |
radios.should.have.length(1); | ||
}); | ||
|
||
it('can start with a row disabled', function () { | ||
renderTable( | ||
<DataTable | ||
{...defaultProps} | ||
selection={[]} | ||
disabledSelection={defaultSelection} | ||
selectRows="radio" | ||
> | ||
{columns.map((columnProps) => ( | ||
<DataTableColumn {...columnProps} key={columnProps.property} /> | ||
))} | ||
</DataTable> | ||
).call(this); | ||
|
||
const tbody = getTable(this.dom).querySelectorAll('tbody')[0]; | ||
const radios = tbody.querySelectorAll('.slds-radio input:disabled'); | ||
radios.should.have.length(1); | ||
}); | ||
|
||
it('can select a row', function (done) { | ||
this.onRowChange = (event, { selection }) => { | ||
selection.should.have.length(1); | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the event fire on a disabled checkbox? It doesn't fire for me.
If the change event never fired, then the consumer doesn't need to worry about filtering.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since checkbox is disabled, it is not triggered
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm asking about this line.
I'm thinking that disabled doesn't mean a row can't be selected. You could force select a row (that is make it selected) and then disable it.
It's up to the application to decide whether to filter by disabled rows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. Makes sense. A row can be preselected but disabled.