mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DateTimePicker: Return cleared value in onChange (#88377)
* DateTimePicker: Return cleared value in onChange * Update story
This commit is contained in:
parent
12e4a94d63
commit
c4aca053e5
@ -80,7 +80,7 @@ export const widgets: Widgets = {
|
|||||||
return (
|
return (
|
||||||
<DateTimePicker
|
<DateTimePicker
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
props?.setValue(e.format(BasicConfig.widgets.datetime.valueFormat));
|
props?.setValue(e?.format(BasicConfig.widgets.datetime.valueFormat));
|
||||||
}}
|
}}
|
||||||
date={dateValue}
|
date={dateValue}
|
||||||
/>
|
/>
|
||||||
|
@ -58,7 +58,9 @@ export const OnlyWorkingHoursEnabled: StoryFn<typeof DateTimePicker> = ({ label,
|
|||||||
showSeconds={showSeconds}
|
showSeconds={showSeconds}
|
||||||
onChange={(newValue) => {
|
onChange={(newValue) => {
|
||||||
action('on change')(newValue);
|
action('on change')(newValue);
|
||||||
setDate(newValue);
|
if (newValue) {
|
||||||
|
setDate(newValue);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@ -81,7 +83,9 @@ export const Basic: StoryFn<typeof DateTimePicker> = ({ label, minDate, maxDate,
|
|||||||
clearable={clearable}
|
clearable={clearable}
|
||||||
onChange={(newValue) => {
|
onChange={(newValue) => {
|
||||||
action('on change')(newValue);
|
action('on change')(newValue);
|
||||||
setDate(newValue);
|
if (newValue) {
|
||||||
|
setDate(newValue);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@ -101,7 +105,9 @@ export const Clearable: StoryFn<typeof DateTimePicker> = ({ label, showSeconds,
|
|||||||
clearable={clearable}
|
clearable={clearable}
|
||||||
onChange={(newValue) => {
|
onChange={(newValue) => {
|
||||||
action('on change')(newValue);
|
action('on change')(newValue);
|
||||||
setDate(newValue);
|
if (newValue) {
|
||||||
|
setDate(newValue);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -35,7 +35,7 @@ export interface Props {
|
|||||||
/** Input date for the component */
|
/** Input date for the component */
|
||||||
date?: DateTime;
|
date?: DateTime;
|
||||||
/** Callback for returning the selected date */
|
/** Callback for returning the selected date */
|
||||||
onChange: (date: DateTime) => void;
|
onChange: (date?: DateTime) => void;
|
||||||
/** label for the input field */
|
/** label for the input field */
|
||||||
label?: ReactNode;
|
label?: ReactNode;
|
||||||
/** Set the latest selectable date */
|
/** Set the latest selectable date */
|
||||||
@ -200,15 +200,10 @@ interface DateTimeCalendarProps {
|
|||||||
disabledSeconds?: () => number[];
|
disabledSeconds?: () => number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InputProps {
|
type InputProps = Pick<Props, 'onChange' | 'label' | 'date' | 'showSeconds' | 'clearable'> & {
|
||||||
label?: ReactNode;
|
|
||||||
date?: DateTime;
|
|
||||||
isFullscreen: boolean;
|
isFullscreen: boolean;
|
||||||
onChange: (date: DateTime) => void;
|
|
||||||
onOpen: (event: FormEvent<HTMLElement>) => void;
|
onOpen: (event: FormEvent<HTMLElement>) => void;
|
||||||
showSeconds?: boolean;
|
};
|
||||||
clearable?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
type InputState = {
|
type InputState = {
|
||||||
value: string;
|
value: string;
|
||||||
@ -249,7 +244,8 @@ const DateTimeInput = React.forwardRef<HTMLInputElement, InputProps>(
|
|||||||
|
|
||||||
const clearInternalDate = useCallback(() => {
|
const clearInternalDate = useCallback(() => {
|
||||||
setInternalDate({ value: '', invalid: false });
|
setInternalDate({ value: '', invalid: false });
|
||||||
}, []);
|
onChange();
|
||||||
|
}, [onChange]);
|
||||||
|
|
||||||
const icon = <Button aria-label="Time picker" icon="calendar-alt" variant="secondary" onClick={onOpen} />;
|
const icon = <Button aria-label="Time picker" icon="calendar-alt" variant="secondary" onClick={onOpen} />;
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user