Skip to content

Commit

Permalink
Do not accept a and p sympbols in not am/pm mode (#1183)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmtrKovalenko authored Jul 15, 2019
1 parent a9067fd commit 5b7e485
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/src/DateTimePicker/DateTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export const DateTimePicker = makePurePicker<DateTimePickerProps>({
export const KeyboardDateTimePicker = makeKeyboardPicker<KeyboardDateTimePickerProps>({
useOptions,
DefaultToolbarComponent: DateTimePickerToolbar,
getCustomProps: props => ({
refuse: props.ampm ? /[^\dap]+/gi : /[^\d]+/gi,
}),
});

DateTimePicker.defaultProps = defaultProps;
Expand Down
9 changes: 7 additions & 2 deletions lib/src/Picker/WrappedKeyboardPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ export type WrappedKeyboardPickerProps = DateValidationProps &
BaseKeyboardPickerProps &
ExtendWrapper<KeyboardDateInputProps>;

export interface MakePickerOptions {
export interface MakePickerOptions<T> {
useOptions: (props: any) => StateHookOptions;
getCustomProps?: (props: T) => Partial<T>;
DefaultToolbarComponent: React.ComponentType<ToolbarComponentProps>;
}

// Mostly duplicate of ./WrappedPurePicker.tsx to enable tree-shaking of keyboard logic
// TODO investigate how to reduce duplications
export function makeKeyboardPicker<T extends any>({
useOptions,
getCustomProps,
DefaultToolbarComponent,
}: MakePickerOptions): React.FC<WrappedKeyboardPickerProps & T> {
}: MakePickerOptions<WrappedKeyboardPickerProps & T>): React.FC<WrappedKeyboardPickerProps & T> {
function WrappedKeyboardPicker(props: WrappedKeyboardPickerProps & T) {
const {
allowKeyboardControl,
Expand Down Expand Up @@ -71,6 +73,8 @@ export function makeKeyboardPicker<T extends any>({
...other
} = props;

const injectedProps = getCustomProps ? getCustomProps(props) : {};

const options = useOptions(props);
const { pickerProps, inputProps, wrapperProps } = useKeyboardPickerState(props, options);

Expand All @@ -79,6 +83,7 @@ export function makeKeyboardPicker<T extends any>({
variant={variant}
InputComponent={KeyboardDateInput}
DateInputProps={inputProps}
{...injectedProps}
{...wrapperProps}
{...other}
>
Expand Down
6 changes: 5 additions & 1 deletion lib/src/Picker/WrappedPurePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export type WrappedPurePickerProps = DateValidationProps &

export function makePurePicker<T extends any>({
useOptions,
getCustomProps,
DefaultToolbarComponent,
}: MakePickerOptions): React.FC<WrappedPurePickerProps & T> {
}: MakePickerOptions<WrappedPurePickerProps & T>): React.FC<WrappedPurePickerProps & T> {
function WrappedPurePicker(props: WrappedPurePickerProps & T) {
const {
allowKeyboardControl,
Expand Down Expand Up @@ -62,6 +63,8 @@ export function makePurePicker<T extends any>({
...other
} = props;

const injectedProps = getCustomProps ? getCustomProps(props) : {};

const options = useOptions(props);
const { pickerProps, inputProps, wrapperProps } = usePickerState(props, options);

Expand All @@ -71,6 +74,7 @@ export function makePurePicker<T extends any>({
InputComponent={PureDateInput}
DateInputProps={inputProps}
{...wrapperProps}
{...injectedProps}
{...other}
>
<Picker
Expand Down
3 changes: 3 additions & 0 deletions lib/src/TimePicker/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export const TimePicker = makePurePicker<TimePickerViewsProps>({
export const KeyboardTimePicker = makeKeyboardPicker<TimePickerViewsProps>({
useOptions,
DefaultToolbarComponent: TimePickerToolbar,
getCustomProps: props => ({
refuse: props.ampm ? /[^\dap]+/gi : /[^\d]+/gi,
}),
});

TimePicker.defaultProps = defaultProps;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/_shared/KeyboardDateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface KeyboardDateInputProps
maskChar?: string;
/**
* Refuse values regexp
* @default /[^\dap]+/gi
* @default /[^\d]+/gi
*/
refuse?: RegExp;
/**
Expand Down Expand Up @@ -61,7 +61,7 @@ const KeyboardDateInput: React.FunctionComponent<KeyboardDateInputProps> = ({
InputProps,
mask,
maskChar = '_',
refuse = /[^\dap]+/gi,
refuse = /[^\d]+/gi,
format,
keyboardIcon,
disabled,
Expand Down

0 comments on commit 5b7e485

Please sign in to comment.