@@ -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 >
0 commit comments