Skip to content

Commit

Permalink
fix: fix DateTimePicker text capitalization
Browse files Browse the repository at this point in the history
  • Loading branch information
HellWolf93 committed Sep 16, 2021
1 parent c06f469 commit e897ee5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
10 changes: 9 additions & 1 deletion src/components/DateTimePicker/helpers/formatDateTime.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import capitalizeFirstLetter from './capitalizeFirstLetter';

/* eslint-disable no-console */
const FORMATS = {
small: { year: '2-digit', month: 'numeric', day: 'numeric' },
Expand All @@ -18,7 +20,13 @@ export default function formatDateTime(
const options = FORMATS[formatStyle] || FORMATS.medium;
const value = typeof date === 'string' ? new Date(date) : date;
const timeFormat = hour24 ? timeFormat24h : timeFormat12h;
return new Intl.DateTimeFormat(locale, { ...options, ...timeFormat }).format(value);
const formattedDatetime = new Intl.DateTimeFormat(locale, {
...options,
...timeFormat,
}).format(value);
return formatStyle === 'large'
? capitalizeFirstLetter(formattedDatetime)
: formattedDatetime;
} catch (error) {
console.error(error);
return '';
Expand Down
4 changes: 2 additions & 2 deletions src/components/DateTimePicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import React, { useRef, useEffect, useState, useImperativeHandle, useContext } from 'react';
import PropTypes from 'prop-types';
import withReduxForm from '../../libs/hocs/withReduxForm';
import Input from '../Input';
import DateTimeIcon from './icon';
import DateTimePickerModal from './pickerModal';
import formatDateTime from './helpers/formatDateTime';
import { ENTER_KEY, SPACE_KEY } from '../../libs/constants';
import StyledContainer from './styled/container';
import StyledInput from './styled/input';
import { AppContext } from '../Application/context';
import { getLocale } from '../../libs/utils';

Expand Down Expand Up @@ -105,7 +105,7 @@ const DateTimePicker = React.forwardRef((props, ref) => {

return (
<StyledContainer id={id} className={className} style={style}>
<StyledInput
<Input
ref={inputRef}
label={label}
placeholder={placeholder}
Expand Down
8 changes: 0 additions & 8 deletions src/components/DateTimePicker/styled/input.js

This file was deleted.

0 comments on commit e897ee5

Please sign in to comment.