Skip to content

Commit 241fb14

Browse files
committed
Fixed primefaces#733 - Rename defaultLabel to placeholder in MultiSelect
1 parent a793a83 commit 241fb14

File tree

4 files changed

+60
-41
lines changed

4 files changed

+60
-41
lines changed

src/components/multiselect/MultiSelect.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
overflow: hidden;
4242
}
4343

44+
.p-multiselect .p-multiselect-label-empty {
45+
overflow: hidden;
46+
visibility: hidden;
47+
}
48+
4449
.p-multiselect.p-disabled .p-multiselect-trigger,
4550
.p-multiselect.p-disabled .p-multiselect-label {
4651
cursor: auto

src/components/multiselect/MultiSelect.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface MultiSelectProps {
99
style?: object;
1010
className?: string;
1111
scrollHeight?: string;
12-
defaultLabel?: string;
12+
placeholder?: string;
1313
disabled?: boolean;
1414
filter?: boolean;
1515
tabIndex?: boolean;

src/components/multiselect/MultiSelect.js

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class MultiSelect extends Component {
1818
style: null,
1919
className: null,
2020
scrollHeight: '200px',
21-
defaultLabel: 'Choose',
21+
placeholder: null,
2222
disabled: false,
2323
filter: false,
2424
tabIndex: '0',
@@ -39,7 +39,7 @@ export class MultiSelect extends Component {
3939
style: PropTypes.object,
4040
className: PropTypes.string,
4141
scrollHeight: PropTypes.string,
42-
defaultLabel: PropTypes.string,
42+
placeholder: PropTypes.string,
4343
disabled: PropTypes.bool,
4444
filter: PropTypes.bool,
4545
tabIndex: PropTypes.string,
@@ -260,25 +260,6 @@ export class MultiSelect extends Component {
260260
return this.findSelectionIndex(this.getOptionValue(option)) !== -1;
261261
}
262262

263-
getLabel() {
264-
let label;
265-
266-
if(this.props.value && this.props.value.length) {
267-
label = '';
268-
for(let i = 0; i < this.props.value.length; i++) {
269-
if(i !== 0) {
270-
label += ',';
271-
}
272-
label += this.findLabelByValue(this.props.value[i]);
273-
}
274-
}
275-
else {
276-
label = this.props.defaultLabel;
277-
}
278-
279-
return label;
280-
}
281-
282263
findLabelByValue(val) {
283264
let label = null;
284265

@@ -386,24 +367,29 @@ export class MultiSelect extends Component {
386367
return this.props.optionLabel ? ObjectUtils.resolveFieldData(option, this.props.optionLabel) : option.label;
387368
}
388369

389-
renderTooltip() {
390-
this.tooltip = new Tooltip({
391-
target: this.container,
392-
content: this.props.tooltip,
393-
options: this.props.tooltipOptions
394-
});
370+
isEmpty() {
371+
return !this.props.value || this.props.value.length === 0;
395372
}
396373

397-
renderHeader(items) {
398-
return (
399-
<MultiSelectHeader filter={this.props.filter} filterValue={this.state.filter} onFilter={this.onFilter}
400-
onClose={this.onCloseClick} onToggleAll={this.onToggleAll} allChecked={this.isAllChecked(items)} />
401-
);
374+
getLabel() {
375+
let label;
376+
377+
if (!this.isEmpty()) {
378+
label = '';
379+
for(let i = 0; i < this.props.value.length; i++) {
380+
if(i !== 0) {
381+
label += ',';
382+
}
383+
label += this.findLabelByValue(this.props.value[i]);
384+
}
385+
}
386+
387+
return label;
402388
}
403389

404-
renderLabel() {
405-
if(this.props.selectedItemTemplate) {
406-
if(this.props.value && this.props.value.length) {
390+
getLabelContent() {
391+
if (this.props.selectedItemTemplate) {
392+
if( this.props.value && this.props.value.length) {
407393
return this.props.value.map((val, index) => {
408394
return (
409395
<React.Fragment key={index}>{this.props.selectedItemTemplate(val)}</React.Fragment>
@@ -419,6 +405,36 @@ export class MultiSelect extends Component {
419405
}
420406
}
421407

408+
renderTooltip() {
409+
this.tooltip = new Tooltip({
410+
target: this.container,
411+
content: this.props.tooltip,
412+
options: this.props.tooltipOptions
413+
});
414+
}
415+
416+
renderHeader(items) {
417+
return (
418+
<MultiSelectHeader filter={this.props.filter} filterValue={this.state.filter} onFilter={this.onFilter}
419+
onClose={this.onCloseClick} onToggleAll={this.onToggleAll} allChecked={this.isAllChecked(items)} />
420+
);
421+
}
422+
423+
renderLabel() {
424+
const empty = this.isEmpty();
425+
const content = this.getLabelContent();
426+
const className = classNames('p-multiselect-label', {
427+
'p-placeholder': empty && this.props.placeholder,
428+
'p-multiselect-label-empty': empty && !this.props.placeholder && !this.props.selectedItemTemplate}
429+
);
430+
431+
return (
432+
<div className="p-multiselect-label-container">
433+
<label className={className}>{content||this.props.placeholder||'empty'}</label>
434+
</div>
435+
);
436+
}
437+
422438
render() {
423439
let className = classNames('p-multiselect p-component', this.props.className, {'p-disabled': this.props.disabled});
424440
let label = this.renderLabel();
@@ -446,9 +462,7 @@ export class MultiSelect extends Component {
446462
<div className="p-hidden-accessible">
447463
<input readOnly type="text" onFocus={this.onFocus} onBlur={this.onBlur} ref={el => this.focusInput = el} />
448464
</div>
449-
<div className="p-multiselect-label-container" title="Choose">
450-
<label className="p-multiselect-label">{label}</label>
451-
</div>
465+
{label}
452466
<div className="p-multiselect-trigger">
453467
<span className="p-multiselect-trigger-icon pi pi-chevron-down p-c"></span>
454468
</div>

src/showcase/multiselect/MultiSelectDemo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ selectedCarTemplate(option) {
269269
<td>Height of the viewport in pixels, a scrollbar is defined if height of list exceeds this value.</td>
270270
</tr>
271271
<tr>
272-
<td>defaultLabel</td>
272+
<td>placeholder</td>
273273
<td>string</td>
274-
<td>Choose</td>
274+
<td>null</td>
275275
<td>Label to display when there are no selections.</td>
276276
</tr>
277277
<tr>

0 commit comments

Comments
 (0)