Skip to content

Commit

Permalink
refactor: fixed errored typings
Browse files Browse the repository at this point in the history
  • Loading branch information
Gururajj77 committed Nov 4, 2024
1 parent cfb3c7a commit dcab08e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
49 changes: 39 additions & 10 deletions packages/react/src/components/DataTable/TableSelectRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,29 +87,58 @@ const TableSelectRow = ({
}: TableSelectRowProps) => {
const prefix = usePrefix();
const uniqueNameId = useId();

const handleRadioChange = onChange
? (
value: string | number | undefined,
name: string | undefined,
event: React.ChangeEvent<HTMLInputElement>
) => {
// Convert the radio value to boolean for consistency
onChange(!!value, name || '', event);
}
: undefined;

const handleCheckboxChange = onChange
? (
checked: boolean,
name: string,
event: React.ChangeEvent<HTMLInputElement>
) => {
onChange(checked, name, event);
}
: undefined;

const selectionInputProps = {
id,
name: name ? name : uniqueNameId,
onClick: onSelect,
onChange,
checked,
disabled,
};
const InlineInputComponent = radio ? RadioButton : InlineCheckbox;
// const InlineInputComponent = radio ? RadioButton : InlineCheckbox;

const labelValue = ariaLabel || deprecatedAriaLabel || '';
const tableSelectRowClasses = classNames(`${prefix}--table-column-checkbox`, {
...(className && { [className]: true }),
[`${prefix}--table-column-radio`]: radio,
});
return (
<td className={tableSelectRowClasses} aria-live="off">
<InlineInputComponent
{...selectionInputProps}
{...(radio && {
labelText: ariaLabel || deprecatedAriaLabel,
hideLabel: true,
})}
{...(!radio && { 'aria-label': ariaLabel || deprecatedAriaLabel })}
/>
{radio ? (
<RadioButton
{...selectionInputProps}
labelText={labelValue}
onChange={handleRadioChange}
hideLabel={true}
/>
) : (
<InlineCheckbox
{...selectionInputProps}
aria-label={labelValue}
onChange={handleCheckboxChange}
/>
)}
</td>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface InlineCheckboxProps {
/*
* Specify the label for the control
*/
'aria-label': string;
'aria-label'?: string;

/**
* Deprecated, please use `aria-label` instead.
Expand Down Expand Up @@ -154,7 +154,7 @@ InlineCheckbox.propTypes = {
/**
* Specify the label for the control
*/
['aria-label']: PropTypes.string.isRequired,
['aria-label']: PropTypes.string,

/**
* Deprecated, please use `aria-label` instead.
Expand Down

0 comments on commit dcab08e

Please sign in to comment.