Skip to content

Commit

Permalink
polish :)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Mar 13, 2020
1 parent 24624f4 commit 013fce5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/pages/api-docs/autocomplete.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
| <span class="prop-name">multiple</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, `value` must be an array and the menu will support multiple selections. |
| <span class="prop-name">noOptionsText</span> | <span class="prop-type">node</span> | <span class="prop-default">'No options'</span> | Text to display when there are no options.<br>For localization purposes, you can use the provided [translations](/guides/localization/). |
| <span class="prop-name">onChange</span> | <span class="prop-type">func</span> | | Callback fired when the value changes.<br><br>**Signature:**<br>`function(event: object, value: T, reason: string) => void`<br>*event:* The event source of the callback.<br>*value:* null<br>*reason:* One of "create-option", "select-option", "remove-option", "blur" or "clear". |
| <span class="prop-name">onClose</span> | <span class="prop-type">func</span> | | Callback fired when the popup requests to be closed. Use in controlled mode (see open).<br><br>**Signature:**<br>`function(event: object) => void`<br>*event:* The event source of the callback. |
| <span class="prop-name">onClose</span> | <span class="prop-type">func</span> | | Callback fired when the popup requests to be closed. Use in controlled mode (see open).<br><br>**Signature:**<br>`function(event: object, reason: string) => void`<br>*event:* The event source of the callback.<br>*reason:* Can be: `"toggleInput"`, `"escape"`, `"select-option"`, `"blur"`. |
| <span class="prop-name">onInputChange</span> | <span class="prop-type">func</span> | | Callback fired when the input value changes.<br><br>**Signature:**<br>`function(event: object, value: string, reason: string) => void`<br>*event:* The event source of the callback.<br>*value:* The new value of the text input.<br>*reason:* Can be: `"input"` (user input), `"reset"` (programmatic change), `"clear"`. |
| <span class="prop-name">onOpen</span> | <span class="prop-type">func</span> | | Callback fired when the popup requests to be opened. Use in controlled mode (see open).<br><br>**Signature:**<br>`function(event: object) => void`<br>*event:* The event source of the callback. |
| <span class="prop-name">open</span> | <span class="prop-type">bool</span> | | Control the popup` open state. |
Expand Down
4 changes: 2 additions & 2 deletions docs/src/pages/components/autocomplete/GitHubLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Popper from '@material-ui/core/Popper';
import SettingsIcon from '@material-ui/icons/Settings';
import CloseIcon from '@material-ui/icons/Close';
import DoneIcon from '@material-ui/icons/Done';
import Autocomplete from '@material-ui/lab/Autocomplete';
import Autocomplete, { AutocompleteCloseReason } from '@material-ui/lab/Autocomplete';
import ButtonBase from '@material-ui/core/ButtonBase';
import InputBase from '@material-ui/core/InputBase';

Expand Down Expand Up @@ -130,7 +130,7 @@ export default function GitHubLabel() {
setAnchorEl(event.currentTarget);
};

const handleClose = (event: any, reason: any) => {
const handleClose = (event: React.ChangeEvent<{}>, reason: AutocompleteCloseReason) => {
if (reason === 'toggleInput') {
return;
}
Expand Down
8 changes: 5 additions & 3 deletions packages/material-ui-lab/src/Autocomplete/Autocomplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import * as React from 'react';
import { StandardProps } from '@material-ui/core';
import { PopperProps } from '@material-ui/core/Popper';
import {
ChangeReason,
AutocompleteCloseReason,
ChangeDetails,
UseAutocompleteCommonProps,
ChangeReason,
createFilterOptions,
InputChangeReason,
UseAutocompleteCommonProps,
UseAutocompleteProps,
} from '../useAutocomplete';
export { ChangeReason, ChangeDetails, createFilterOptions };
export { AutocompleteCloseReason, InputChangeReason, ChangeReason, ChangeDetails, createFilterOptions };

export interface RenderOptionState {
inputValue: string;
Expand Down
1 change: 1 addition & 0 deletions packages/material-ui-lab/src/Autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ Autocomplete.propTypes = {
* Use in controlled mode (see open).
*
* @param {object} event The event source of the callback.
* @param {string} reason Can be: `"toggleInput"`, `"escape"`, `"select-option"`, `"blur"`.
*/
onClose: PropTypes.func,
/**
Expand Down
27 changes: 12 additions & 15 deletions packages/material-ui-lab/src/useAutocomplete/useAutocomplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,17 @@ export interface UseAutocompleteCommonProps<T> {
* Use in controlled mode (see open).
*
* @param {object} event The event source of the callback.
* @param {string} reason Can be: `"toggleInput"`, `"escape"`, `"select-option"`, `"blur"`.
*/
onClose?: (
event: React.ChangeEvent<{}>,
reason?: 'toggleInput' | 'escape' | 'select-option',
) => void;
onClose?: (event: React.ChangeEvent<{}>, reason: AutocompleteCloseReason) => void;
/**
* Callback fired when the input value changes.
*
* @param {object} event The event source of the callback.
* @param {string} value The new value of the text input.
* @param {string} reason Can be: `"input"` (user input), `"reset"` (programmatic change), `"clear"`.
*/
onInputChange?: (
event: React.ChangeEvent<{}>,
value: string,
reason: 'input' | 'reset' | 'clear',
) => void;
onInputChange?: (event: React.ChangeEvent<{}>, value: string, reason: AutocompleteInputChangeReason) => void;
/**
* Callback fired when the popup requests to be opened.
* Use in controlled mode (see open).
Expand All @@ -169,10 +163,13 @@ export interface UseAutocompleteCommonProps<T> {
selectOnFocus?: boolean;
}

export type ChangeReason = 'create-option' | 'select-option' | 'remove-option' | 'clear' | 'blur';
export interface ChangeDetails<T = string> {
export type AutocompleteChangeReason = 'create-option' | 'select-option' | 'remove-option' | 'clear' | 'blur';
export interface AutocompleteChangeDetails<T = string> {
option: T;
}
export type AutocompleteCloseReason = 'toggleInput' | 'escape' | 'select-option' | 'blur';
export type AutocompleteInputChangeReason = 'input' | 'reset' | 'clear';

export interface UseAutocompleteMultipleProps<T> extends UseAutocompleteCommonProps<T> {
/**
* If `true`, `value` must be an array and the menu will support multiple selections.
Expand All @@ -199,8 +196,8 @@ export interface UseAutocompleteMultipleProps<T> extends UseAutocompleteCommonPr
onChange?: (
event: React.ChangeEvent<{}>,
value: T[],
reason: ChangeReason,
details?: ChangeDetails<T>,
reason: AutocompleteChangeReason,
details?: AutocompleteChangeDetails<T>,
) => void;
}

Expand Down Expand Up @@ -230,8 +227,8 @@ export interface UseAutocompleteSingleProps<T> extends UseAutocompleteCommonProp
onChange?: (
event: React.ChangeEvent<{}>,
value: T | null,
reason: ChangeReason,
details?: ChangeDetails<T>,
reason: AutocompleteChangeReason,
details?: AutocompleteChangeDetails<T>,
) => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ export default function useAutocomplete(props) {
resetInputValue(event, value);
}

handleClose(event, 'toggleInput');
handleClose(event, 'blur');
};

const handleInputChange = event => {
Expand Down
4 changes: 3 additions & 1 deletion packages/material-ui/src/Snackbar/Snackbar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface SnackbarOrigin {
horizontal: 'left' | 'center' | 'right';
}

export type CloseReason = 'timeout' | 'clickaway';

export interface SnackbarProps
extends StandardProps<
React.HTMLAttributes<HTMLDivElement> & Partial<TransitionHandlerProps>,
Expand All @@ -21,7 +23,7 @@ export interface SnackbarProps
ContentProps?: Partial<SnackbarContentProps>;
disableWindowBlurListener?: boolean;
message?: SnackbarContentProps['message'];
onClose?: (event: React.SyntheticEvent<any>, reason: string) => void;
onClose?: (event: React.SyntheticEvent<any>, reason: CloseReason) => void;
onMouseEnter?: React.MouseEventHandler<any>;
onMouseLeave?: React.MouseEventHandler<any>;
open: boolean;
Expand Down

0 comments on commit 013fce5

Please sign in to comment.