@@ -101,6 +101,8 @@ const propTypes = {
101
101
PropTypes . element ,
102
102
PropTypes . arrayOf ( PropTypes . element ) ,
103
103
] ) . isRequired ,
104
+
105
+ renderInput : PropTypes . elementType ,
104
106
}
105
107
106
108
class MentionsInput extends React . Component {
@@ -177,7 +179,7 @@ class MentionsInput extends React.Component {
177
179
)
178
180
}
179
181
180
- setContainerElement = ( el ) => {
182
+ setContainerElement = el => {
181
183
this . containerElement = el
182
184
}
183
185
@@ -223,28 +225,35 @@ class MentionsInput extends React.Component {
223
225
}
224
226
225
227
renderControl = ( ) => {
226
- let { singleLine, style } = this . props
228
+ let { singleLine, style, renderInput } = this . props
227
229
let inputProps = this . getInputProps ( )
228
230
229
231
return (
230
232
< div { ...style ( 'control' ) } >
231
233
{ this . renderHighlighter ( ) }
232
- { singleLine
234
+ { renderInput
235
+ ? this . renderCustom ( inputProps )
236
+ : singleLine
233
237
? this . renderInput ( inputProps )
234
238
: this . renderTextarea ( inputProps ) }
235
239
</ div >
236
240
)
237
241
}
238
242
239
- renderInput = ( props ) => {
243
+ renderCustom = props => {
244
+ let { renderInput : RenderInput } = this . props
245
+ return < RenderInput ref = { this . setInputRef } { ...props } />
246
+ }
247
+
248
+ renderInput = props => {
240
249
return < input type = "text" ref = { this . setInputRef } { ...props } />
241
250
}
242
251
243
- renderTextarea = ( props ) => {
252
+ renderTextarea = props => {
244
253
return < textarea ref = { this . setInputRef } { ...props } />
245
254
}
246
255
247
- setInputRef = ( el ) => {
256
+ setInputRef = el => {
248
257
this . inputElement = el
249
258
const { inputRef } = this . props
250
259
if ( typeof inputRef === 'function' ) {
@@ -254,7 +263,7 @@ class MentionsInput extends React.Component {
254
263
}
255
264
}
256
265
257
- setSuggestionsElement = ( el ) => {
266
+ setSuggestionsElement = el => {
258
267
this . suggestionsElement = el
259
268
}
260
269
@@ -278,7 +287,7 @@ class MentionsInput extends React.Component {
278
287
scrollFocusedIntoView = { this . state . scrollFocusedIntoView }
279
288
containerRef = { this . setSuggestionsElement }
280
289
suggestions = { this . state . suggestions }
281
- customSuggestionsContainer = { this . props . customSuggestionsContainer }
290
+ customSuggestionsContainer = { this . props . customSuggestionsContainer }
282
291
onSelect = { this . addMention }
283
292
onMouseDown = { this . handleSuggestionsMouseDown }
284
293
onMouseEnter = { this . handleSuggestionsMouseEnter }
@@ -319,11 +328,11 @@ class MentionsInput extends React.Component {
319
328
)
320
329
}
321
330
322
- setHighlighterElement = ( el ) => {
331
+ setHighlighterElement = el => {
323
332
this . highlighterElement = el
324
333
}
325
334
326
- handleCaretPositionChange = ( position ) => {
335
+ handleCaretPositionChange = position => {
327
336
this . setState ( { caretPosition : position } )
328
337
}
329
338
@@ -487,9 +496,9 @@ class MentionsInput extends React.Component {
487
496
}
488
497
489
498
// Handle input element's change event
490
- handleChange = ( ev ) => {
499
+ handleChange = ev => {
491
500
isComposing = false
492
- if ( isIE ( ) ) {
501
+ if ( isIE ( ) ) {
493
502
// if we are inside iframe, we need to find activeElement within its contentDocument
494
503
const currentDocument =
495
504
( document . activeElement && document . activeElement . contentDocument ) ||
@@ -560,7 +569,7 @@ class MentionsInput extends React.Component {
560
569
}
561
570
562
571
// Handle input element's select event
563
- handleSelect = ( ev ) => {
572
+ handleSelect = ev => {
564
573
// keep track of selection range / caret position
565
574
this . setState ( {
566
575
selectionStart : ev . target . selectionStart ,
@@ -584,7 +593,7 @@ class MentionsInput extends React.Component {
584
593
this . props . onSelect ( ev )
585
594
}
586
595
587
- handleKeyDown = ( ev ) => {
596
+ handleKeyDown = ev => {
588
597
// do not intercept key events if the suggestions overlay is not shown
589
598
const suggestionsCount = countSuggestions ( this . state . suggestions )
590
599
@@ -626,7 +635,7 @@ class MentionsInput extends React.Component {
626
635
}
627
636
}
628
637
629
- shiftFocus = ( delta ) => {
638
+ shiftFocus = delta => {
630
639
const suggestionsCount = countSuggestions ( this . state . suggestions )
631
640
632
641
this . setState ( {
@@ -642,7 +651,7 @@ class MentionsInput extends React.Component {
642
651
const { result, queryInfo } = Object . values ( suggestions ) . reduce (
643
652
( acc , { results, queryInfo } ) => [
644
653
...acc ,
645
- ...results . map ( ( result ) => ( { result, queryInfo } ) ) ,
654
+ ...results . map ( result => ( { result, queryInfo } ) ) ,
646
655
] ,
647
656
[ ]
648
657
) [ focusIndex ]
@@ -654,7 +663,7 @@ class MentionsInput extends React.Component {
654
663
} )
655
664
}
656
665
657
- handleBlur = ( ev ) => {
666
+ handleBlur = ev => {
658
667
const clickedSuggestion = this . _suggestionsMouseDown
659
668
this . _suggestionsMouseDown = false
660
669
@@ -674,11 +683,11 @@ class MentionsInput extends React.Component {
674
683
this . props . onBlur ( ev , clickedSuggestion )
675
684
}
676
685
677
- handleSuggestionsMouseDown = ( ev ) => {
686
+ handleSuggestionsMouseDown = ev => {
678
687
this . _suggestionsMouseDown = true
679
688
}
680
689
681
- handleSuggestionsMouseEnter = ( focusIndex ) => {
690
+ handleSuggestionsMouseEnter = focusIndex => {
682
691
this . setState ( {
683
692
focusIndex,
684
693
scrollFocusedIntoView : false ,
@@ -687,7 +696,11 @@ class MentionsInput extends React.Component {
687
696
688
697
updateSuggestionsPosition = ( ) => {
689
698
let { caretPosition } = this . state
690
- const { suggestionsPortalHost, allowSuggestionsAboveCursor, forceSuggestionsAboveCursor } = this . props
699
+ const {
700
+ suggestionsPortalHost,
701
+ allowSuggestionsAboveCursor,
702
+ forceSuggestionsAboveCursor,
703
+ } = this . props
691
704
692
705
if ( ! caretPosition || ! this . suggestionsElement ) {
693
706
return
@@ -739,9 +752,9 @@ class MentionsInput extends React.Component {
739
752
// is small enough to NOT cover up the caret
740
753
if (
741
754
( allowSuggestionsAboveCursor &&
742
- top + suggestions . offsetHeight > viewportHeight &&
755
+ top + suggestions . offsetHeight > viewportHeight &&
743
756
suggestions . offsetHeight < top - caretHeight ) ||
744
- forceSuggestionsAboveCursor
757
+ forceSuggestionsAboveCursor
745
758
) {
746
759
position . top = Math . max ( 0 , top - suggestions . offsetHeight - caretHeight )
747
760
} else {
@@ -761,12 +774,12 @@ class MentionsInput extends React.Component {
761
774
// is small enough to NOT cover up the caret
762
775
if (
763
776
( allowSuggestionsAboveCursor &&
764
- viewportRelative . top -
765
- highlighter . scrollTop +
766
- suggestions . offsetHeight >
767
- viewportHeight &&
768
- suggestions . offsetHeight <
769
- caretOffsetParentRect . top - caretHeight - highlighter . scrollTop ) ||
777
+ viewportRelative . top -
778
+ highlighter . scrollTop +
779
+ suggestions . offsetHeight >
780
+ viewportHeight &&
781
+ suggestions . offsetHeight <
782
+ caretOffsetParentRect . top - caretHeight - highlighter . scrollTop ) ||
770
783
forceSuggestionsAboveCursor
771
784
) {
772
785
position . top = top - suggestions . offsetHeight - caretHeight
0 commit comments