@material-ui/lab
Version:
Material-UI Lab - Incubator for Material-UI React components.
53 lines (52 loc) • 1.52 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import PropTypes from 'prop-types';
import { onSpaceOrEnter } from './utils';
import { useUtils } from './hooks/useUtils';
import { getDisplayDate, getTextFieldAriaText } from './text-field-helper'; // make `variant` optional
export const PureDateInput = ({
containerRef,
disabled,
forwardedRef,
getOpenDialogAriaText = getTextFieldAriaText,
inputFormat,
InputProps,
label,
openPicker: onOpen,
rawValue,
renderInput,
TextFieldProps = {},
validationError
}) => {
const utils = useUtils();
const PureDateInputProps = React.useMemo(() => _extends({}, InputProps, {
readOnly: true
}), [InputProps]);
const inputValue = getDisplayDate(utils, rawValue, inputFormat);
return renderInput(_extends({
label,
disabled,
ref: containerRef,
inputRef: forwardedRef,
error: validationError,
InputProps: PureDateInputProps,
inputProps: {
disabled,
readOnly: true,
'aria-readonly': true,
'aria-label': getOpenDialogAriaText(rawValue, utils),
value: inputValue,
onClick: onOpen,
onKeyDown: onSpaceOrEnter(onOpen)
}
}, TextFieldProps));
};
PureDateInput.propTypes = {
acceptRegex: PropTypes.instanceOf(RegExp),
getOpenDialogAriaText: PropTypes.func,
mask: PropTypes.string,
OpenPickerButtonProps: PropTypes.object,
openPickerIcon: PropTypes.node,
renderInput: PropTypes.func.isRequired,
rifmFormatter: PropTypes.func
};