-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(DatePicker): hide error when date cleared and not required + show…
… error when cleared and required
- Loading branch information
1 parent
12f946b
commit 0a971ab
Showing
3 changed files
with
39 additions
and
4 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
26 changes: 26 additions & 0 deletions
26
packages/react-core/src/components/DatePicker/examples/DatePickerControlledRequired.tsx
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,26 @@ | ||
import React from 'react'; | ||
import { Button, DatePicker, Flex, FlexItem } from '@patternfly/react-core'; | ||
|
||
export const DatePickerControlled: React.FunctionComponent = () => { | ||
const initialValue = '2020-03-17'; | ||
const [value, setValue] = React.useState(initialValue); | ||
return ( | ||
<React.Fragment> | ||
<DatePicker | ||
requiredDateOptions={{ isRequired: true, emptyDateText: 'Date is required' }} | ||
value={value} | ||
onChange={(_event, value) => setValue(value)} | ||
/> | ||
<br /> | ||
<br /> | ||
<Flex> | ||
<FlexItem> | ||
<Button onClick={() => setValue(initialValue)}>Reset date</Button> | ||
</FlexItem> | ||
<FlexItem> | ||
<Button onClick={() => setValue('')}>Clear date</Button> | ||
</FlexItem> | ||
</Flex> | ||
</React.Fragment> | ||
); | ||
}; |