Skip to content

Commit

Permalink
Fixed #2195 - Add empty property to MultiStateCheckbox
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Jul 16, 2021
1 parent 52d6e8f commit a5bd2d2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions api-generator/components/multistatecheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ const MultiStateCheckboxProps = [
default: 'false',
description: 'When present, it specifies that the element value cannot be altered.'
},
{
name: 'empty',
type: 'boolean',
default: 'true',
description: 'If false, the empty state is skipped in the chekbox.'
},
{
name: 'tooltip',
type: 'any',
Expand Down
1 change: 1 addition & 0 deletions src/components/multistatecheckbox/MultiStateCheckbox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface MultiStateCheckboxProps {
className?: string;
disabled?: boolean;
readOnly?: boolean;
empty?: boolean;
tooltip?: string;
tooltipOptions?: TooltipOptions;
ariaLabelledBy?: string;
Expand Down
8 changes: 7 additions & 1 deletion src/components/multistatecheckbox/MultiStateCheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class MultiStateCheckbox extends Component {
className: null,
disabled: false,
readOnly: false,
empty: true,
tooltip: null,
tooltipOptions: null,
ariaLabelledBy: null,
Expand All @@ -39,6 +40,7 @@ export class MultiStateCheckbox extends Component {
className: PropTypes.string,
disabled: PropTypes.bool,
readOnly: PropTypes.bool,
empty: PropTypes.bool,
tooltip: PropTypes.string,
tooltipOptions: PropTypes.object,
ariaLabelledBy: PropTypes.string,
Expand Down Expand Up @@ -89,7 +91,7 @@ export class MultiStateCheckbox extends Component {
findNextOption() {
if (this.props.options) {
const { index } = this.findSelectedOptionMap();
return index === this.props.options.length - 1 ? null : this.props.options[index + 1];
return index === this.props.options.length - 1 ? (this.props.empty ? null : this.props.options[0]) : this.props.options[index + 1];
}

return null;
Expand Down Expand Up @@ -140,6 +142,10 @@ export class MultiStateCheckbox extends Component {
if (this.props.tooltip && !this.props.disabled) {
this.renderTooltip();
}

if (!this.props.empty && this.props.value === null) {
this.toggle();
}
}

componentDidUpdate(prevProps) {
Expand Down
6 changes: 6 additions & 0 deletions src/showcase/multistatecheckbox/MultiStateCheckboxDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ import {MultiStateCheckbox} from 'primereact/multistatecheckbox';
<td>false</td>
<td>When present, it specifies that the element value cannot be altered.</td>
</tr>
<tr>
<td>empty</td>
<td>boolean</td>
<td>true</td>
<td>If false, the empty state is skipped in the chekbox.</td>
</tr>
<tr>
<td>tooltip</td>
<td>any</td>
Expand Down

0 comments on commit a5bd2d2

Please sign in to comment.