Skip to content
Open
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
36 changes: 19 additions & 17 deletions src/TimePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default class Picker extends Component {
id: PropTypes.string,
inputIcon: PropTypes.node,
clearIcon: PropTypes.node,
customInput: PropTypes.element,
};

static defaultProps = {
Expand Down Expand Up @@ -332,9 +333,11 @@ export default class Picker extends Component {
inputReadOnly,
inputIcon,
popupStyle,
customInput,
} = this.props;
const { open, value } = this.state;
const popupClassName = this.getPopupClassName();
const Input = customInput || <input type="text" />;
return (
<Trigger
prefixCls={`${prefixCls}-panel`}
Expand All @@ -352,23 +355,22 @@ export default class Picker extends Component {
onPopupVisibleChange={this.onVisibleChange}
>
<span className={classNames(prefixCls, className)} style={style}>
<input
className={`${prefixCls}-input`}
ref={this.saveInputRef}
type="text"
placeholder={placeholder}
name={name}
onKeyDown={this.onKeyDown}
disabled={disabled}
value={(value && value.format(this.getFormat())) || ''}
autoComplete={autoComplete}
onFocus={onFocus}
onBlur={onBlur}
autoFocus={autoFocus}
onChange={noop}
readOnly={!!inputReadOnly}
id={id}
/>
{React.cloneElement(Input, {
className: [Input.className, `${prefixCls}-input`].join(' ').trim(),
ref: this.saveInputRef,
placeholder: placeholder,
name: name,
onKeyDown: this.onKeyDown,
disabled: disabled,
value: (value && value.format(this.getFormat())) || '',
autoComplete: autoComplete,
onFocus: onFocus,
onBlur: onBlur,
autoFocus: autoFocus,
onChange: noop,
readOnly: !!inputReadOnly,
id: id,
})}
{inputIcon || <span className={`${prefixCls}-icon`} />}
{this.renderClearButton()}
</span>
Expand Down
7 changes: 7 additions & 0 deletions tests/TimePicker.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ describe('TimePicker', () => {
});
expect(picker.find('.rc-time-picker').text()).toBe('test-select');
});

it ('support custom input element', () => {
const picker = renderPicker({
customInput: <div className="custom-wrapper"><input type="text"/></div>,
});
expect(picker.find('.custom-wrapper')).toBeDefined();
});
});

describe('render panel to body (without seconds)', () => {
Expand Down