Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demo/src/examples/Examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const users = [
{
id: 'jesse',
display: 'Jesse Pinkman',
disabled: true,
},
{
id: 'gus',
Expand Down
4 changes: 4 additions & 0 deletions demo/src/examples/defaultStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export default {
'&focused': {
backgroundColor: '#cee4e5',
},
'&disabled': {
opacity: '0.3',
cursor: 'default',
},
},
},
}
3 changes: 2 additions & 1 deletion src/MentionsInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,11 @@ class MentionsInput extends React.Component {
}

addMention = (
{ id, display },
{ id, display, disabled },
{ childIndex, querySequenceStart, querySequenceEnd, plainTextValue }
) => {
// Insert mention in the marked up value at the correct position
if(disabled) return;
const value = this.props.value || ''
const config = readConfigFromChildren(this.props.children)
const mentionsChild = Children.toArray(this.props.children)[childIndex]
Expand Down
3 changes: 2 additions & 1 deletion src/Suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Suggestion extends Component {
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
.isRequired,
display: PropTypes.string,
disabled: PropTypes.string
}),
]).isRequired,
renderSuggestion: PropTypes.func,
Expand Down Expand Up @@ -96,7 +97,7 @@ const styled = defaultStyle(
{
cursor: 'pointer',
},
props => ({ '&focused': props.focused })
props => ({ '&focused': props.focused, '&disabled': props.disabled })
)

export default styled(Suggestion)
5 changes: 4 additions & 1 deletion src/SuggestionsOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class SuggestionsOverlay extends Component {
renderSuggestion={renderSuggestion}
suggestion={result}
focused={isFocused}
disabled={result.disabled}
onClick={() => this.select(result, queryInfo)}
onMouseEnter={() => this.handleMouseEnter(index)}
/>
Expand All @@ -148,7 +149,9 @@ class SuggestionsOverlay extends Component {
}

select = (suggestion, queryInfo) => {
this.props.onSelect(suggestion, queryInfo)
if(!suggestion.disabled) {
this.props.onSelect(suggestion, queryInfo)
}
}

setUlElement = (el) => {
Expand Down