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(react-examples): Add focus to DatePicker examples when clicking the Clear button #16430

Merged
merged 1 commit into from
Jan 22, 2021
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { DatePicker } from '@fluentui/react-date-time';
import { DatePicker, IDatePicker } from '@fluentui/react-date-time';
import { DefaultButton } from '@fluentui/react/lib/compat/Button';
import { mergeStyleSets } from '@fluentui/react/lib/Styling';

Expand All @@ -14,9 +14,11 @@ const onFormatDate = (date?: Date): string => {

export const DatePickerFormatExample: React.FunctionComponent = () => {
const [value, setValue] = React.useState<Date | undefined>();
const datePickerRef = React.useRef<IDatePicker>(null);

const onClick = React.useCallback((): void => {
setValue(undefined);
datePickerRef.current?.focus();
}, []);

const onParseDateFromString = React.useCallback(
Expand Down Expand Up @@ -46,6 +48,7 @@ export const DatePickerFormatExample: React.FunctionComponent = () => {
example, we are formatting and parsing dates as dd/MM/yy.
</div>
<DatePicker
componentRef={datePickerRef}
label="Start date"
allowTextInput
ariaLabel="Select a date. Input format is day slash month slash year."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const DatePickerInputExample: React.FunctionComponent = () => {

const onClick = React.useCallback((): void => {
setValue(undefined);
datePickerRef.current?.focus();
}, []);

return (
Expand All @@ -24,12 +25,12 @@ export const DatePickerInputExample: React.FunctionComponent = () => {
pressing Enter will open the DatePicker.
</div>
<DatePicker
componentRef={datePickerRef}
label="Start date"
allowTextInput
ariaLabel="Select a date"
value={value}
onSelectDate={setValue as (date: Date | null | undefined) => void}
componentRef={datePickerRef}
className={styles.control}
/>
<DefaultButton onClick={onClick} text="Clear" />
Expand Down