Skip to content

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

Merged

Conversation

meizibupt
Copy link
Contributor

@meizibupt meizibupt commented Aug 1, 2023

Fixes #3125

Additional description

add option to disable radio/checkbox for datatable
image
image


CONTRIBUTOR checklist (do not remove)

Please complete for every pull request

  • First-time contributors should sign the Contributor License Agreement. It's a fancy way of saying that you are giving away your contribution to this project. If you haven't before, wait a few minutes and a bot will comment on this pull request with instructions.
  • npm run lint:fix has been run and linting passes.
  • Mocha, Jest (Storyshots), and components/component-docs.json CI tests pass (npm test).
  • Tests have been added for new props to prevent regressions in the future. See readme.
  • Review the appropriate Storybook stories. Open http://localhost:9001/.
  • Review tests are passing in the browser. Open http://localhost:8001/.
  • Review markup conforms to SLDS by looking at DOM snapshot strings.

REVIEWER checklist (do not remove)

  • CircleCI tests pass. This includes linting, Mocha, Jest, Storyshots, and components/component-docs.json tests.
  • Tests have been added for new props to prevent regressions in the future. See readme.
  • Review the appropriate Storybook stories. Open http://localhost:9001/.
  • The Accessibility panel of each Storybook story has 0 violations (aXe). Open http://localhost:9001/.
  • Review tests are passing in the browser. Open http://localhost:8001/.
  • Review markup conforms to SLDS by looking at DOM snapshot strings.
Required only if there are markup / UX changes
  • Add year-first date and commit SHA to last-slds-markup-review in package.json and push.
  • Request a review of the deployed Heroku app by the Salesforce UX Accessibility Team.
  • Add year-first review date, and commit SHA, last-accessibility-review, to package.json and push.
  • While the contributor's branch is checked out, run npm run local-update within locally cloned site repo to confirm the site will function correctly at the next release.

@meizibupt meizibupt changed the title add support for disabling data table selection add support for disabling data table selection (checkbox/radio) Aug 1, 2023
@interactivellama
Copy link
Contributor

interactivellama commented Aug 10, 2023

@meizibupt I'm going to look at this a little more later tonight, but when I pulled it down and used it. The main issue I'm seeing is that Nav to Edit mode and try to set focus on the disabled item. To reproduce, navigate with the arrow keys and then press enter. Focus visually disappears/gets lost.

I would recommend disabling switching to edit mode, essentially ignoring the switch to edit mode

@interactivellama
Copy link
Contributor

Demo:
2023-08-10 17 39 45

@meizibupt
Copy link
Contributor Author

meizibupt commented Aug 10, 2023

@meizibupt I'm going to look at this a little more later tonight, but when I pulled it down and used it. The main issue I'm seeing is that Nav to Edit mode and try to set focus on the disabled item. To reproduce, navigate with the arrow keys and then press enter. Focus visually disappears/gets lost.

I would recommend disabling switching to edit mode, essentially ignoring the switch to edit mode

thanks for reviewing. can you be more specific. what do you mean by disabling edit mode? do you mean disallowing navigating to the disabled checkbox?

@interactivellama
Copy link
Contributor

Yes, as in ignore the enter key if the child is disabled which is what is done when the content is only text in a cell.

Please check me on this, but I believe returning a normal disabled <Checkbox> instead of <InteractiveCheckbox> here https://github.com/salesforce/design-system-react/blob/master/components/data-table/private/row.jsx#L145
would disable the focus and treat it as non-actionable / non-editable.

Same with Radio here https://github.com/salesforce/design-system-react/blob/master/components/data-table/private/row.jsx#L145

@@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the single select example for consumers. Please keep radio or choose another example.

Copy link
Contributor Author

@meizibupt meizibupt Aug 11, 2023

Choose a reason for hiding this comment

The 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

selection: [],
disabledSelection: [items[0]],
};

handleChanged = (event, data) => {
Copy link
Contributor

@interactivellama interactivellama Aug 11, 2023

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.

Copy link
Contributor Author

@meizibupt meizibupt Aug 11, 2023

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

Copy link
Contributor

@interactivellama interactivellama Aug 11, 2023

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.

const selections = data.selection.filter(
			(s) => !this.state.disabledSelection.includes(s)
		);

It's up to the application to decide whether to filter by disabled rows.

Copy link
Contributor Author

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.

const disabledRows = tbody.querySelectorAll(
'.slds-checkbox input:disabled'
);
disabledRows.should.have.length(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should spy the onRowChange and make sure it doesn't fire OR make sure the data.selection parameter is still 0 in length. See can select a row below and negate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated test

@interactivellama interactivellama self-requested a review August 14, 2023 21:41
@interactivellama
Copy link
Contributor

Great addition! @meizibupt

@interactivellama interactivellama merged commit e6e832b into salesforce:master Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants