Skip to content

Commit

Permalink
Fix #4492: Datatable check/radio respect isDataSelectable (#4493)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Jun 7, 2023
1 parent 8adf29c commit 58d6170
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
24 changes: 22 additions & 2 deletions components/lib/datatable/BodyCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,30 @@ export const BodyCell = React.memo((props) => {
content = showSelection && (
<>
{selectionMode === 'single' && (
<RowRadioButton checked={props.selected} onChange={onRadioChange} tabIndex={props.tabIndex} tableSelector={props.tableSelector} ariaLabel={label} ptCallbacks={props.ptCallbacks} metaData={props.metaData} />
<RowRadioButton
column={props.column}
checked={props.selected}
disabled={!props.isSelectable({ data: props.rowData, index: props.rowIndex })}
onChange={onRadioChange}
tabIndex={props.tabIndex}
tableSelector={props.tableSelector}
ariaLabel={label}
ptCallbacks={props.ptCallbacks}
metaData={props.metaData}
/>
)}
{selectionMode === 'multiple' && (
<RowCheckbox checked={props.selected} onChange={onCheckboxChange} tabIndex={props.tabIndex} ariaLabel={label} checkIcon={props.checkIcon} ptCallbacks={props.ptCallbacks} metaData={props.metaData} />
<RowCheckbox
column={props.column}
checked={props.selected}
disabled={!props.isSelectable({ data: props.rowData, index: props.rowIndex })}
onChange={onCheckboxChange}
tabIndex={props.tabIndex}
ariaLabel={label}
checkIcon={props.checkIcon}
ptCallbacks={props.ptCallbacks}
metaData={props.metaData}
/>
)}
</>
);
Expand Down
8 changes: 4 additions & 4 deletions components/lib/datatable/RowCheckbox.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { IconUtils, classNames, mergeProps } from '../utils/Utils';
import { CheckIcon } from '../icons/check';
import { ColumnBase } from '../column/ColumnBase';
import { CheckIcon } from '../icons/check';
import { IconUtils, classNames, mergeProps } from '../utils/Utils';

export const RowCheckbox = React.memo((props) => {
const [focusedState, setFocusedState] = React.useState(false);
Expand Down Expand Up @@ -45,8 +45,8 @@ export const RowCheckbox = React.memo((props) => {
}
};

const className = classNames('p-checkbox p-component', { 'p-checkbox-focused': focusedState });
const boxClassName = classNames('p-checkbox-box p-component', { 'p-highlight': props.checked, 'p-disabled': props.disabled, 'p-focus': focusedState });
const className = classNames('p-checkbox p-component', { 'p-checkbox-focused': focusedState, 'p-disabled': props.disabled });
const boxClassName = classNames('p-checkbox-box p-component', { 'p-highlight': props.checked, 'p-focus': focusedState });
const iconClassName = 'p-checkbox-icon';
const checkboxIconProps = mergeProps(
{
Expand Down
6 changes: 3 additions & 3 deletions components/lib/datatable/RowRadioButton.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { classNames, DomHandler, mergeProps } from '../utils/Utils';
import { ColumnBase } from '../column/ColumnBase';
import { classNames, DomHandler, mergeProps } from '../utils/Utils';

export const RowRadioButton = React.memo((props) => {
const [focusedState, setFocusedState] = React.useState(false);
Expand Down Expand Up @@ -49,8 +49,8 @@ export const RowRadioButton = React.memo((props) => {
onClick(event);
};

const className = classNames('p-radiobutton p-component', { 'p-radiobutton-focused': focusedState });
const boxClassName = classNames('p-radiobutton-box p-component', { 'p-highlight': props.checked, 'p-focus': focusedState, 'p-disabled': props.disabled });
const className = classNames('p-radiobutton p-component', { 'p-radiobutton-focused': focusedState, 'p-disabled': props.disabled });
const boxClassName = classNames('p-radiobutton-box p-component', { 'p-highlight': props.checked, 'p-focus': focusedState });
const name = `${props.tableSelector}_dt_radio`;
const radiobuttonWrapperProps = mergeProps(
{
Expand Down

0 comments on commit 58d6170

Please sign in to comment.