Skip to content

Commit

Permalink
feat(calendar-input): changed input-mask (#1267)
Browse files Browse the repository at this point in the history
  • Loading branch information
praiz committed Feb 16, 2021
1 parent c523d50 commit 855ca13
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 2 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion src/calendar-input/__snapshots__/calendar-input.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ exports[`calendar-input should render without problems 1`] = `
<ForwardRef(ThemedComponent(IconCalendar)) />
</ForwardRef(ThemedComponent(IconButton))>
}
mask="11.11.1111"
mask="31.11.2111"
maskFormatCharacters={
Object {
"2": Object {
"validate": [Function],
},
"3": Object {
"validate": [Function],
},
}
}
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
Expand Down
16 changes: 15 additions & 1 deletion src/calendar-input/calendar-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { isNodeOutsideElement } from '../lib/window';
import {
parseDate, calculateMonth, changeDateFormat, isInputDateSupported,
} from './utils';
import { FormatCharacters } from '../masked-input/mask';
import performance from '../performance';

/**
Expand All @@ -33,6 +34,18 @@ const CUSTOM_DATE_FORMAT = 'DD.MM.YYYY';
const NATIVE_DATE_FORMAT = 'YYYY-MM-DD';
const IS_BROWSER = typeof window !== 'undefined';
const SUPPORTS_INPUT_TYPE_DATE = IS_BROWSER && isInputDateSupported();
const maskFormatCharacters: FormatCharacters = {
2: {
validate(char) {
return /[1-2]/.test(char);
},
},
3: {
validate(char) {
return /[0-3]/.test(char);
},
},
};

export type CalendarInputProps = {

Expand Down Expand Up @@ -365,7 +378,8 @@ export class CalendarInput extends React.Component<CalendarInputProps> {
className={ this.cn('custom-control') }
disabledAttr={ this.isNativeInput() || this.isMobilePopup() }
focused={ this.state.isInputFocused || this.state.isCalendarFocused }
mask="11.11.1111"
mask="31.11.2111"
maskFormatCharacters={ maskFormatCharacters }
size={ this.props.size }
type="tel"
pattern="[0-9.]*"
Expand Down

0 comments on commit 855ca13

Please sign in to comment.