Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/src/prop-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,17 @@
"required": false,
"type": { "name": "Partial<InputAdornmentProps>" }
},
"KeyboardButtonProps": {
"defaultValue": null,
"description": "Props to pass to keyboard adornment button",
"name": "KeyboardButtonProps",
"parent": {
"fileName": "/Users/dmitrijkovalenko/dev/material-ui-pickers/lib/src/_shared/DateTextField.tsx",
"name": "DateTextFieldProps"
},
"required": false,
"type": { "name": "Partial<KeyboardButtonProps>" }
},
"adornmentPosition": {
"defaultValue": null,
"description": "Specifies position of keyboard button adornment",
Expand Down
6 changes: 6 additions & 0 deletions lib/src/__tests__/_shared/DateTextField.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { WithStyles } from '@material-ui/core';
import { createMount } from '@material-ui/core/test-utils';
import { ShallowWrapper } from 'enzyme';
import * as React from 'react';
Expand Down Expand Up @@ -42,6 +43,7 @@ describe('DateTextField keyboard mode', () => {
format="dd/MM/yyyy"
classes={{}}
keyboard
KeyboardButtonProps={{ 'aria-label': 'bar' }}
clearable
onClear={jest.fn()}
onChange={jest.fn()}
Expand All @@ -68,6 +70,10 @@ describe('DateTextField keyboard mode', () => {
component.find('TextField').prop<any>('InputProps').endAdornment.props.children.props.disabled
).toBe(true);
});

it('Should spread properties onto the InputAdornmentButton', () => {
expect(component.find('WithStyles(IconButton)').props()['aria-label']).toBe('bar');
});
});

describe('DateTextField with custom TextField', () => {
Expand Down
9 changes: 7 additions & 2 deletions lib/src/_shared/DateTextField.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as PropTypes from 'prop-types';
import * as React from 'react';

import IconButton from '@material-ui/core/IconButton';
import IconButton, { IconButtonProps as MuiIconButtonProps } from '@material-ui/core/IconButton';
import { InputProps as InputPropsType } from '@material-ui/core/Input';
import InputAdornment, {
InputAdornmentProps as MuiInputAdornmentProps,
Expand Down Expand Up @@ -62,6 +62,8 @@ export interface DateTextFieldProps
| React.ReactType<React.HTMLAttributes<any>>;
/** Props to pass to keyboard input adornment */
InputAdornmentProps?: Partial<MuiInputAdornmentProps>;
/** Props to pass to keyboard adornment button */
KeyboardButtonProps?: Partial<MuiIconButtonProps>;
/** Specifies position of keyboard button adornment */
adornmentPosition?: MuiInputAdornmentProps['position'];
onClick: (e: React.SyntheticEvent) => void;
Expand Down Expand Up @@ -103,6 +105,7 @@ export class DateTextField extends React.PureComponent<DateTextFieldProps> {
invalidDateMessage: PropTypes.node,
TextFieldComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
InputAdornmentProps: PropTypes.object,
KeyboardButtonProps: PropTypes.object,
adornmentPosition: PropTypes.oneOf(['start', 'end']),
onError: PropTypes.func,
onInputChange: PropTypes.func,
Expand All @@ -127,6 +130,7 @@ export class DateTextField extends React.PureComponent<DateTextFieldProps> {
maxDateMessage: 'Date should not be after maximal date',
TextFieldComponent: TextField,
InputAdornmentProps: {},
KeyboardButtonProps: {},
adornmentPosition: 'end' as MuiInputAdornmentProps['position'],
keepCharPositions: false,
};
Expand Down Expand Up @@ -257,6 +261,7 @@ export class DateTextField extends React.PureComponent<DateTextFieldProps> {
invalidDateMessage,
invalidLabel,
keyboard,
KeyboardButtonProps,
keyboardIcon,
labelFunc,
mask,
Expand Down Expand Up @@ -290,7 +295,7 @@ export class DateTextField extends React.PureComponent<DateTextFieldProps> {
if (keyboard) {
localInputProps[`${adornmentPosition}Adornment`] = (
<InputAdornment position={adornmentPosition!} {...InputAdornmentProps}>
<IconButton disabled={disabled} onClick={this.openPicker}>
<IconButton disabled={disabled} onClick={this.openPicker} {...KeyboardButtonProps}>
{keyboardIcon}
</IconButton>
</InputAdornment>
Expand Down