Skip to content

Commit

Permalink
Fix primefaces#5073: SelectButton: Add allowEmpty property
Browse files Browse the repository at this point in the history
  • Loading branch information
habubey committed Oct 10, 2023
1 parent 0b2cd55 commit 4d7fc00
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions components/lib/selectbutton/SelectButton.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react';
import { PrimeReactContext } from '../api/Api';
import { Tooltip } from '../tooltip/Tooltip';
import { DomHandler, mergeProps, ObjectUtils } from '../utils/Utils';
import { SelectButtonBase } from './SelectButtonBase';
import { SelectButtonItem } from './SelectButtonItem';
import { PrimeReactContext } from '../api/Api';

export const SelectButton = React.memo(
React.forwardRef((inProps, ref) => {
Expand All @@ -23,7 +23,7 @@ export const SelectButton = React.memo(

let selected = isSelected(event.option);

if (selected && !props.unselectable) {
if (selected && (!props.unselectable || props.allowEmpty)) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions components/lib/selectbutton/SelectButtonBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const SelectButtonBase = ComponentBase.extend({
tabIndex: null,
multiple: false,
unselectable: true,
allowEmpty: true,
disabled: false,
style: null,
className: null,
Expand Down
5 changes: 5 additions & 0 deletions components/lib/selectbutton/selectbutton.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ export interface SelectButtonProps extends Omit<React.DetailedHTMLProps<React.In
* @defaultValue true
*/
unselectable?: boolean | undefined;
/**
* Whether selection can not be cleared.
* @defaultValue true
*/
allowEmpty?: boolean | undefined;
/**
* When present, it specifies that the element should be disabled.
* @defaultValue false
Expand Down

0 comments on commit 4d7fc00

Please sign in to comment.