Skip to content
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

fix(component): allow 0 as values in select and fix docs #257

Merged
merged 2 commits into from
Nov 12, 2019
Merged
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
4 changes: 2 additions & 2 deletions packages/big-design/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class Select<T extends any> extends React.PureComponent<SelectProps<T>, S
const { filterChildren, highlightedItem, inputText } = this.state;

return options.map((option, index) => {
if (!option.content || !option.value) {
if (!option.content || typeof option.value === 'undefined') {
return null;
}

Expand Down Expand Up @@ -466,7 +466,7 @@ export class Select<T extends any> extends React.PureComponent<SelectProps<T>, S
private updatedSelectedItem() {
const { multi, value } = this.props;

if (!value || multi) {
if (typeof value === 'undefined' || multi) {
return this.setState({ inputText: '', selectedElement: null, selectedOptionContent: '' });
}

Expand Down
233 changes: 118 additions & 115 deletions packages/docs/pages/Select/SelectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,43 @@ export default () => (
const handleChange = val => setValue(val);

return (
<Form.Group>
<Select
action={{
actionType: 'destructive',
content: 'Remove Country',
icon: <DeleteIcon />,
onClick: () => null,
}}
filterable={true}
label="Countries"
maxHeight={300}
onItemChange={handleChange}
options={[
{ value: 'us', content: 'United States' },
{ value: 'mx', content: 'Mexico' },
{ value: 'ca', content: 'Canada' },
{ value: 'en', content: 'England' },
{ value: 'fr', content: 'France' },
{ value: 'gr', content: 'Germany' },
{ value: 'ar', content: 'Argentina' },
{ value: 'ru', content: 'Russia', disabled: true },
{ value: 'ch', content: 'Chile' },
{ value: 'bo', content: 'Bolivia' },
{ value: 'jp', content: 'Japan' },
{ value: 'cn', content: 'China' },
{ value: 'sk', content: 'South Korea' },
{ value: 'au', content: 'Australia' },
{ value: 'ug', content: 'Uganda' },
]}
placeholder={'Choose country'}
placement={'bottom-start'}
required
value={value}
/>
</Form.Group>
<Form>
<Form.Group>
<Select
action={{
actionType: 'destructive',
content: 'Remove Country',
icon: <DeleteIcon />,
onClick: () => null,
}}
filterable={true}
label="Countries"
maxHeight={300}
onItemChange={handleChange}
options={[
{ value: 'us', content: 'United States' },
{ value: 'mx', content: 'Mexico' },
{ value: 'ca', content: 'Canada' },
{ value: 'en', content: 'England' },
{ value: 'fr', content: 'France' },
{ value: 'gr', content: 'Germany' },
{ value: 'ar', content: 'Argentina' },
{ value: 'ru', content: 'Russia', disabled: true },
{ value: 'ch', content: 'Chile' },
{ value: 'bo', content: 'Bolivia' },
{ value: 'jp', content: 'Japan' },
{ value: 'cn', content: 'China' },
{ value: 'sk', content: 'South Korea' },
{ value: 'au', content: 'Australia' },
{ value: 'ug', content: 'Uganda' },
]}
placeholder={'Choose country'}
placement={'bottom-start'}
required
value={value}
/>
</Form.Group>
</Form>
);
}}
{/* jsx-to-string:end */}
Expand All @@ -83,25 +85,27 @@ export default () => (
const handleChange = val => setValue(val);

return (
<Form.Group>
<Select
label="States"
maxHeight={300}
multi={true}
onItemChange={handleChange}
options={[
{ value: 'tx', content: 'Texas' },
{ value: 'ca', content: 'California' },
{ value: 'or', content: 'Oregon' },
{ value: 'ar', content: 'Arkansas' },
{ value: 'nv', content: 'Nevada', disabled: true },
]}
placeholder={'Choose states'}
placement={'bottom-start'}
required
value={value}
/>
</Form.Group>
<Form>
<Form.Group>
<Select
label="States"
maxHeight={300}
multi={true}
onItemChange={handleChange}
options={[
{ value: 'tx', content: 'Texas' },
{ value: 'ca', content: 'California' },
{ value: 'or', content: 'Oregon' },
{ value: 'ar', content: 'Arkansas' },
{ value: 'nv', content: 'Nevada', disabled: true },
]}
placeholder={'Choose states'}
placement={'bottom-start'}
required
value={value}
/>
</Form.Group>
</Form>
);
}}
{/* jsx-to-string:end */}
Expand Down Expand Up @@ -195,18 +199,6 @@ export default () => (
placeholder="Default"
required
/>
<Select
label="Select"
onItemChange={() => null}
options={[
{ value: 1, content: 'Option' },
{ value: 2, content: 'Option' },
{ value: 3, content: 'Option' },
{ value: 4, content: 'Option' },
]}
placeholder="Default"
required
/>
<Select
label="Select"
maxHeight={150}
Expand Down Expand Up @@ -246,20 +238,25 @@ export default () => (

<CodePreview>
{/* jsx-to-string:start */}
<Select
disabled
label="Select"
maxHeight={350}
onItemChange={() => null}
options={[
{ value: 1, content: 'Option' },
{ value: 2, content: 'Option' },
{ value: 3, content: 'Option' },
{ value: 4, content: 'Option' },
]}
placeholder="Larger"
required
/>
<Form>
<Form.Group>
<Select
disabled
label="Select"
maxHeight={350}
onItemChange={() => null}
options={[
{ value: 1, content: 'Option' },
{ value: 2, content: 'Option' },
{ value: 3, content: 'Option' },
{ value: 4, content: 'Option' },
]}
placeholder="Larger"
required
/>
</Form.Group>
</Form>

{/* jsx-to-string:end */}
</CodePreview>

Expand All @@ -271,25 +268,29 @@ export default () => (

<CodePreview>
{/* jsx-to-string:start */}
<Select
action={{
actionType: 'destructive',
content: 'Remove Country',
icon: <DeleteIcon />,
onClick: () => null,
}}
label="Countries"
onItemChange={() => null}
options={[
{ value: 'us', content: 'United States' },
{ value: 'mx', content: 'Mexico' },
{ value: 'ca', content: 'Canada' },
{ value: 'en', content: 'England' },
]}
placeholder={'Choose country'}
placement={'bottom-start'}
required
/>
<Form>
<Form.Group>
<Select
action={{
actionType: 'destructive',
content: 'Remove Country',
icon: <DeleteIcon />,
onClick: () => null,
}}
label="Countries"
onItemChange={() => null}
options={[
{ value: 'us', content: 'United States' },
{ value: 'mx', content: 'Mexico' },
{ value: 'ca', content: 'Canada' },
{ value: 'en', content: 'England' },
]}
placeholder={'Choose country'}
placement={'bottom-start'}
required
/>
</Form.Group>
</Form>
{/* jsx-to-string:end */}
</CodePreview>

Expand All @@ -301,22 +302,24 @@ export default () => (

<CodePreview>
{/* jsx-to-string:start */}
<Form.Group>
<Select
label="Countries"
error="Need to choose a country before proceeding"
onItemChange={() => null}
options={[
{ value: 'us', content: 'United States' },
{ value: 'mx', content: 'Mexico' },
{ value: 'ca', content: 'Canada' },
{ value: 'en', content: 'England' },
]}
placeholder={'Choose country'}
placement={'bottom-start'}
required
/>
</Form.Group>
<Form>
<Form.Group>
<Select
label="Countries"
error="Need to choose a country before proceeding"
onItemChange={() => null}
options={[
{ value: 'us', content: 'United States' },
{ value: 'mx', content: 'Mexico' },
{ value: 'ca', content: 'Canada' },
{ value: 'en', content: 'England' },
]}
placeholder={'Choose country'}
placement={'bottom-start'}
required
/>
</Form.Group>
</Form>
{/* jsx-to-string:end */}
</CodePreview>
</>
Expand Down