-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Create-able Select components #3304
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,12 @@ This controlled usage allows you to implement all sorts of advanced behavior on | |
top of the basic `Select` interactions, such as windowed filtering for large | ||
data sets. | ||
|
||
@## Creating new items | ||
|
||
Use the `createItemFromQuery` prop to allow `Select<T>` to create new items. `createItemFromQuery` specifies how to turn a | ||
user-entered query string into an item of type `<T>` that `Select` understands. You should also provide the `createItemRenderer` | ||
prop to render a custom `MenuItem` to indicate that users can create new items. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's add a simple code sample here that demonstrates using both props. |
||
|
||
@## JavaScript API | ||
|
||
@interface ISelectProps | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,4 +119,34 @@ export function selectComponentSuite<P extends IListItemsProps<IFilm>, S>( | |
assert.equal(testProps.onItemSelect.lastCall.args[0], activeItem); | ||
}); | ||
}); | ||
|
||
describe("create", () => { | ||
const testCreateProps = { | ||
...testProps, | ||
createItemFromQuery: sinon.spy(), | ||
createItemRenderer: () => <textarea />, | ||
}; | ||
|
||
it("renders create item if filtering returns empty list", () => { | ||
const wrapper = render({ | ||
...testCreateProps, | ||
items: [], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the real item list so it's actually filtering instead of always being an empty list |
||
noResults: <address />, | ||
query: "non-existent film name", | ||
}); | ||
assert.lengthOf(wrapper.find("address"), 0, "should not find noResults"); | ||
assert.lengthOf(wrapper.find(`textarea`), 1, "should find createItem"); | ||
}); | ||
|
||
it("enter invokes createItemFromQuery", () => { | ||
const wrapper = render({ | ||
...testCreateProps, | ||
items: [], | ||
noResults: <address />, | ||
query: "non-existent film name", | ||
}); | ||
findInput(wrapper).simulate("keyup", { keyCode: Keys.ENTER }); | ||
assert.equal(testCreateProps.createItemFromQuery.args[0][0], "non-existent film name"); | ||
}); | ||
}); | ||
} |
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.
😂