forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inner state for picker modal (mui#1095)
* Use inner state for displayed date in calendar * Make inline pickers controlled by default * Fix tests * Fix deadlock on rendering with usePickerState * Fix crashing on utils change * Fix not applying keydown listener, closes mui#1090 * Update packages 08.06.2019 (mui#1096) * Update packages 08.06.2019 * Fix prettier
- Loading branch information
1 parent
14e2033
commit 48cd17a
Showing
17 changed files
with
247 additions
and
258 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ReactWrapper } from 'enzyme'; | ||
|
||
export const clickOKButton = (component: ReactWrapper<any>) => { | ||
component | ||
.find('ForwardRef(DialogActions) WithStyles(ForwardRef(Button))') | ||
.at(1) | ||
.simulate('click'); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable react-hooks/rules-of-hooks */ | ||
import { useCallback, useState } from 'react'; | ||
import { BasePickerProps } from '../../typings/BasePicker'; | ||
|
||
function makeControlledOpenProps(props: BasePickerProps) { | ||
return { | ||
isOpen: props.open!, | ||
setIsOpen: (newIsOpen: boolean) => { | ||
return newIsOpen ? props.onOpen && props.onOpen() : props.onClose && props.onClose(); | ||
}, | ||
}; | ||
} | ||
|
||
export function useOpenState(props: BasePickerProps) { | ||
if (props.open !== undefined && props.open !== null) { | ||
return makeControlledOpenProps(props); | ||
} | ||
|
||
const [isOpen, setIsOpenState] = useState(false); | ||
// prettier-ignore | ||
const setIsOpen = useCallback((newIsOpen: boolean) => { | ||
setIsOpenState(newIsOpen); | ||
|
||
return newIsOpen | ||
? props.onOpen && props.onOpen() | ||
: props.onClose && props.onClose(); | ||
}, [props]); | ||
|
||
return { isOpen, setIsOpen }; | ||
} |
Oops, something went wrong.