-
Notifications
You must be signed in to change notification settings - Fork 582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support to disable suggestion selection #719
Open
jack-lewin
wants to merge
5
commits into
signavio:master
Choose a base branch
from
jack-lewin:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d7b6534
Added support to disable suggestion selection
jack-lewin eb2192a
Added tests for SuggestionsOverlay component
jack-lewin fd5aedf
Update docs
jack-lewin 247672b
Added changeset
jack-lewin 47b3c68
Handle case where suggestion is a string
jack-lewin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"react-mentions": minor | ||
--- | ||
|
||
Added support to disable suggestion selection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ const users = [ | |
{ | ||
id: 'jesse', | ||
display: 'Jesse Pinkman', | ||
disabled: true, | ||
}, | ||
{ | ||
id: 'gus', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,123 @@ | ||
import { Mention } from './index' | ||
import SuggestionsOverlay from './SuggestionsOverlay' | ||
|
||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
|
||
const suggestions = { | ||
'0': { | ||
queryInfo: { | ||
childIndex: 0, | ||
query: 'en', | ||
querySequenceStart: 0, | ||
querySequenceEnd: 3, | ||
plainTextValue: '@en', | ||
}, | ||
results: [ | ||
{ | ||
id: 'first', | ||
display: 'First entry', | ||
}, | ||
{ | ||
id: 'second', | ||
display: 'Second entry', | ||
disabled: true, | ||
}, | ||
], | ||
}, | ||
} | ||
|
||
const data = [ | ||
{ id: 'first', value: 'First entry' }, | ||
{ id: 'second', value: 'Second entry', disabled: true }, | ||
{ id: 'third', value: 'Third' }, | ||
] | ||
|
||
describe('SuggestionsOverlay', () => { | ||
it.todo('should render a list of all passed suggestions.') | ||
it.todo('should be possible to style the list.') | ||
it.todo('should be possible to apply styles to the items in the list.') | ||
it.todo('should notify when the user clicks on a suggestion.') | ||
it.todo('should be possible to show a loading indicator.') | ||
it.todo('should be possible to style the loading indicator.') | ||
it.todo('should notify when the user enters a suggestion with his mouse.') | ||
let wrapper | ||
const onSelect = jest.fn() | ||
const onMouseEnter = jest.fn() | ||
|
||
beforeEach(() => { | ||
wrapper = mount( | ||
<SuggestionsOverlay | ||
id="foo" | ||
suggestions={suggestions} | ||
onSelect={onSelect} | ||
onMouseEnter={onMouseEnter} | ||
isOpened | ||
> | ||
<Mention trigger="@" data={data} /> | ||
</SuggestionsOverlay> | ||
) | ||
jest.resetAllMocks() | ||
}) | ||
|
||
it('should render a list of all passed suggestions.', () => { | ||
expect(wrapper.find('li').length).toEqual(2) | ||
}) | ||
|
||
it('should be possible to style the list.', () => { | ||
wrapper.setProps({ style: { list: { color: 'red' } } }) | ||
|
||
expect(wrapper.find('ul').props().style.color).toEqual('red') | ||
}) | ||
|
||
it('should be possible to apply styles to the items in the list.', () => { | ||
wrapper.setProps({ style: { item: { color: 'green' } } }) | ||
|
||
expect( | ||
wrapper | ||
.find('li') | ||
.first() | ||
.props().style.color | ||
).toEqual('green') | ||
}) | ||
|
||
it('should notify when the user clicks on a suggestion.', () => { | ||
wrapper | ||
.find('li') | ||
.first() | ||
.simulate('click') | ||
|
||
expect(onSelect).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('should be possible to show a loading indicator.', () => { | ||
wrapper.setProps({ isLoading: true }) | ||
|
||
expect(wrapper.find('div[aria-label="Loading indicator"]').length).toBe(1) | ||
}) | ||
|
||
it('should be possible to style the loading indicator.', () => { | ||
wrapper.setProps({ | ||
isLoading: true, | ||
style: { loadingIndicator: { color: 'purple' } }, | ||
}) | ||
|
||
expect( | ||
wrapper.find('div[aria-label="Loading indicator"]').props().style.color | ||
).toBe('purple') | ||
}) | ||
|
||
it('should notify when the user enters a suggestion with their mouse.', () => { | ||
wrapper | ||
.find('li') | ||
.first() | ||
.simulate('mouseenter') | ||
|
||
expect(onMouseEnter).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('should prevent selecting a disabled suggestion.', () => { | ||
const results = wrapper.find('li') | ||
|
||
expect(results.last().props()['aria-disabled']).toBe(true) | ||
results.last().simulate('click') | ||
expect(onSelect).toHaveBeenCalledTimes(0) | ||
|
||
expect(results.first().props()['aria-disabled']).toBe(false) | ||
results.first().simulate('click') | ||
expect(onSelect).toHaveBeenCalledTimes(1) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you check here if 'suggestion' is string before accessing
disabled
properly, but on a line 74, you don't?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch @crecotun, thanks - I've added 47b3c68 to be more defensive here