Skip to content

Commit

Permalink
[docs] Fix fourth downshift demo not clearing input
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed May 26, 2019
1 parent d2f5000 commit 0e3d77f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
27 changes: 11 additions & 16 deletions docs/src/pages/components/autocomplete/IntegrationDownshift.js
Expand Up @@ -320,6 +320,7 @@ function IntegrationDownshift() {
classes,
label: 'Countries',
InputLabelProps: getLabelProps({ shrink: true }),
InputProps: { onBlur, onFocus },
inputProps,
ref: node => {
popperNode = node;
Expand Down Expand Up @@ -362,7 +363,15 @@ function IntegrationDownshift() {
openMenu,
selectedItem,
}) => {
const { onBlur, onFocus, ...inputProps } = getInputProps({ foo: 1 });
const { onBlur, onChange, onFocus, ...inputProps } = getInputProps({
onChange: event => {
if (event.target.value === '') {
clearSelection();
}
},
onFocus: openMenu,
placeholder: 'With the clear & show empty options',
});

return (
<div className={classes.container}>
Expand All @@ -371,21 +380,7 @@ function IntegrationDownshift() {
classes,
label: 'Countries',
InputLabelProps: getLabelProps({ shrink: true }),
InputProps: {
onBlur,
onFocus: event => {
openMenu();
if (onFocus !== undefined) {
onFocus(event);
}
},
onChange: event => {
if (event.target.value === '') {
clearSelection();
}
},
placeholder: 'With the clear & show empty options',
},
InputProps: { onBlur, onChange, onFocus },
inputProps,
})}

Expand Down
27 changes: 11 additions & 16 deletions docs/src/pages/components/autocomplete/IntegrationDownshift.tsx
Expand Up @@ -339,6 +339,7 @@ function IntegrationDownshift() {
fullWidth: true,
classes,
label: 'Countries',
InputProps: { onBlur, onFocus },
InputLabelProps: getLabelProps({ shrink: true } as any),
inputProps,
ref: node => {
Expand Down Expand Up @@ -381,7 +382,15 @@ function IntegrationDownshift() {
openMenu,
selectedItem,
}) => {
const { onBlur, onFocus, ...inputProps } = getInputProps({ foo: 1 });
const { onBlur, onChange, onFocus, ...inputProps } = getInputProps({
onChange: (event: React.ChangeEvent<HTMLInputElement>) => {
if (event.target.value === '') {
clearSelection();
}
},
onFocus: openMenu,
placeholder: 'With the clear & show empty options',
});

return (
<div className={classes.container}>
Expand All @@ -390,21 +399,7 @@ function IntegrationDownshift() {
classes,
label: 'Countries',
InputLabelProps: getLabelProps({ shrink: true } as any),
InputProps: {
onBlur,
onFocus: event => {
openMenu();
if (onFocus !== undefined) {
onFocus(event as React.FocusEvent<HTMLInputElement>);
}
},
onChange: (event: React.ChangeEvent<HTMLInputElement>) => {
if (event.target.value === '') {
clearSelection();
}
},
placeholder: 'With the clear & show empty options',
},
InputProps: { onBlur, onChange, onFocus },
inputProps,
})}
<div {...getMenuProps()}>
Expand Down

0 comments on commit 0e3d77f

Please sign in to comment.