@clayui/time-picker 3.52.0 → 3.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { InternalDispatch } from '@clayui/shared';
1
2
  import React from 'react';
2
3
  declare type ConfigMaxMin = {
3
4
  max: number;
@@ -18,7 +19,7 @@ export declare type Input = {
18
19
  hours: '--' | string;
19
20
  minutes: '--' | string;
20
21
  };
21
- interface IProps extends React.HTMLAttributes<HTMLDivElement> {
22
+ interface IProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {
22
23
  ariaLabels?: {
23
24
  ampm: string;
24
25
  hours: string;
@@ -32,13 +33,16 @@ interface IProps extends React.HTMLAttributes<HTMLDivElement> {
32
33
  use24Hours: Config;
33
34
  };
34
35
  disabled?: boolean;
36
+ defaultValue?: Input;
35
37
  icon?: boolean;
36
- onInputChange: (values: Input) => void;
38
+ onChange?: InternalDispatch<Input>;
39
+ onInputChange?: InternalDispatch<Input>;
37
40
  name?: string;
38
- values: Input;
39
41
  spritemap?: string;
40
42
  timezone?: string;
41
43
  use12Hours?: boolean;
44
+ values?: Input;
45
+ value?: Input;
42
46
  }
43
47
  declare const ClayTimePicker: React.FunctionComponent<IProps>;
44
48
  export default ClayTimePicker;
package/lib/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
@@ -15,7 +17,11 @@ var _shared = require("@clayui/shared");
15
17
 
16
18
  var _classnames = _interopRequireDefault(require("classnames"));
17
19
 
18
- var _react = _interopRequireDefault(require("react"));
20
+ var _react = _interopRequireWildcard(require("react"));
21
+
22
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
+
24
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
25
 
20
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
27
 
@@ -76,6 +82,7 @@ var DEFAULT_CONFIG = {
76
82
  }
77
83
  }
78
84
  };
85
+ var regex = /^\d+$/;
79
86
 
80
87
  var ClayTimePicker = function ClayTimePicker(_ref) {
81
88
  var _ref$ariaLabels = _ref.ariaLabels,
@@ -91,45 +98,57 @@ var ClayTimePicker = function ClayTimePicker(_ref) {
91
98
  config = _ref$config === void 0 ? DEFAULT_CONFIG : _ref$config,
92
99
  _ref$disabled = _ref.disabled,
93
100
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
101
+ _ref$defaultValue = _ref.defaultValue,
102
+ defaultValue = _ref$defaultValue === void 0 ? {
103
+ hours: DEFAULT_VALUE,
104
+ minutes: DEFAULT_VALUE
105
+ } : _ref$defaultValue,
94
106
  _ref$icon = _ref.icon,
95
107
  icon = _ref$icon === void 0 ? false : _ref$icon,
96
108
  name = _ref.name,
109
+ onChange = _ref.onChange,
110
+ onInputChange = _ref.onInputChange,
97
111
  spritemap = _ref.spritemap,
98
112
  timezone = _ref.timezone,
99
113
  _ref$use12Hours = _ref.use12Hours,
100
114
  use12Hours = _ref$use12Hours === void 0 ? false : _ref$use12Hours,
101
- _ref$values = _ref.values,
102
- values = _ref$values === void 0 ? {
103
- hours: DEFAULT_VALUE,
104
- minutes: DEFAULT_VALUE
105
- } : _ref$values,
106
- _ref$onInputChange = _ref.onInputChange,
107
- onInputChange = _ref$onInputChange === void 0 ? function () {} : _ref$onInputChange;
108
- var useConfig = config[use12Hours ? 'use12Hours' : 'use24Hours'];
115
+ value = _ref.value,
116
+ values = _ref.values;
117
+
118
+ var _useInternalState = (0, _shared.useInternalState)({
119
+ defaultName: 'defaultValue',
120
+ defaultValue: defaultValue,
121
+ handleName: 'onChange',
122
+ name: 'value',
123
+ onChange: onChange !== null && onChange !== void 0 ? onChange : onInputChange,
124
+ value: value !== null && value !== void 0 ? value : values
125
+ }),
126
+ _useInternalState2 = _slicedToArray(_useInternalState, 2),
127
+ internalValue = _useInternalState2[0],
128
+ setValue = _useInternalState2[1];
109
129
 
110
- var _React$useState = _react.default.useState(false),
111
- _React$useState2 = _slicedToArray(_React$useState, 2),
112
- actionVisible = _React$useState2[0],
113
- setActionVisible = _React$useState2[1];
130
+ var useConfig = config[use12Hours ? 'use12Hours' : 'use24Hours'];
114
131
 
115
- var _React$useState3 = _react.default.useState(false),
116
- _React$useState4 = _slicedToArray(_React$useState3, 2),
117
- isFocused = _React$useState4[0],
118
- setIsFocused = _React$useState4[1];
132
+ var _useState = (0, _react.useState)(false),
133
+ _useState2 = _slicedToArray(_useState, 2),
134
+ actionVisible = _useState2[0],
135
+ setActionVisible = _useState2[1];
119
136
 
120
- var elementRef = _react.default.useRef(null);
137
+ var _useState3 = (0, _react.useState)(false),
138
+ _useState4 = _slicedToArray(_useState3, 2),
139
+ isFocused = _useState4[0],
140
+ setIsFocused = _useState4[1];
121
141
 
142
+ var elementRef = (0, _react.useRef)(null);
122
143
  var defaultFocused = {
123
144
  configName: TimeType.hours,
124
145
  focused: false
125
146
  };
126
147
 
127
- var _React$useState5 = _react.default.useState(defaultFocused),
128
- _React$useState6 = _slicedToArray(_React$useState5, 2),
129
- currentInputFocused = _React$useState6[0],
130
- setCurrentInputFocused = _React$useState6[1];
131
-
132
- var regex = /^\d+$/;
148
+ var _useState5 = (0, _react.useState)(defaultFocused),
149
+ _useState6 = _slicedToArray(_useState5, 2),
150
+ currentInputFocused = _useState6[0],
151
+ setCurrentInputFocused = _useState6[1];
133
152
 
134
153
  var handleMaxAndMin = function handleMaxAndMin(value, config) {
135
154
  var newValue = value.substring(value.length - 2, value.length);
@@ -148,14 +167,14 @@ var ClayTimePicker = function ClayTimePicker(_ref) {
148
167
  var config = useConfig[configName];
149
168
  var intrinsicValue = Number(value);
150
169
 
151
- var setValue = function setValue(newValue) {
170
+ var onValue = function onValue(newValue) {
152
171
  var newVal = configName === TimeType.ampm ? newValue : handleMaxAndMin(String(newValue), config);
153
- return onInputChange(_objectSpread(_objectSpread({}, values), {}, _defineProperty({}, configName, String(newVal).padStart(2, '0'))));
172
+ return setValue(_objectSpread(_objectSpread({}, internalValue), {}, _defineProperty({}, configName, String(newVal).padStart(2, '0'))));
154
173
  };
155
174
 
156
175
  switch (event.key) {
157
176
  case 'Backspace':
158
- setValue(DEFAULT_VALUE);
177
+ onValue(DEFAULT_VALUE);
159
178
  break;
160
179
 
161
180
  case 'ArrowUp':
@@ -163,9 +182,9 @@ var ClayTimePicker = function ClayTimePicker(_ref) {
163
182
  event.stopPropagation();
164
183
 
165
184
  if (configName === TimeType.ampm) {
166
- setValue(config.pm);
185
+ onValue(config.pm);
167
186
  } else {
168
- setValue(value !== DEFAULT_VALUE ? intrinsicValue + 1 : config.min);
187
+ onValue(value !== DEFAULT_VALUE ? intrinsicValue + 1 : config.min);
169
188
  }
170
189
 
171
190
  break;
@@ -175,9 +194,9 @@ var ClayTimePicker = function ClayTimePicker(_ref) {
175
194
  event.stopPropagation();
176
195
 
177
196
  if (configName === TimeType.ampm) {
178
- setValue(config.am);
197
+ onValue(config.am);
179
198
  } else {
180
- setValue(value !== DEFAULT_VALUE ? intrinsicValue - 1 : config.max);
199
+ onValue(value !== DEFAULT_VALUE ? intrinsicValue - 1 : config.max);
181
200
  }
182
201
 
183
202
  break;
@@ -188,9 +207,9 @@ var ClayTimePicker = function ClayTimePicker(_ref) {
188
207
  var minFirstDigit = config.min;
189
208
  var keyVal = intrinsicValue < minFirstDigit ? minFirstDigit : event.key;
190
209
  var newVal = Number(value) > maxSecondDigit ? "0".concat(keyVal) : (value && value !== DEFAULT_VALUE ? value : '') + keyVal;
191
- setValue(newVal);
210
+ onValue(newVal);
192
211
  } else if (configName === TimeType.ampm && (event.key === 'a' || event.key === 'p')) {
193
- setValue(event.key === 'a' ? config.am : config.pm);
212
+ onValue(event.key === 'a' ? config.am : config.pm);
194
213
  }
195
214
 
196
215
  break;
@@ -200,7 +219,7 @@ var ClayTimePicker = function ClayTimePicker(_ref) {
200
219
  var handleAction = function handleAction(direction) {
201
220
  var configName = currentInputFocused.configName;
202
221
  var config = useConfig[configName];
203
- var prevValue = values[configName];
222
+ var prevValue = internalValue[configName];
204
223
  var value;
205
224
 
206
225
  if (configName === TimeType.ampm) {
@@ -213,7 +232,7 @@ var ClayTimePicker = function ClayTimePicker(_ref) {
213
232
  configName: configName,
214
233
  focused: true
215
234
  });
216
- onInputChange(_objectSpread(_objectSpread({}, values), {}, _defineProperty({}, configName, String(value).padStart(2, '0'))));
235
+ setValue(_objectSpread(_objectSpread({}, internalValue), {}, _defineProperty({}, configName, String(value).padStart(2, '0'))));
217
236
  };
218
237
 
219
238
  var handleDocumentClick = function handleDocumentClick(event) {
@@ -233,14 +252,13 @@ var ClayTimePicker = function ClayTimePicker(_ref) {
233
252
  setIsFocused(true);
234
253
  };
235
254
 
236
- _react.default.useEffect(function () {
255
+ (0, _react.useEffect)(function () {
237
256
  document.addEventListener('click', handleDocumentClick);
238
257
  return function () {
239
258
  document.removeEventListener('click', handleDocumentClick);
240
259
  };
241
260
  }, []);
242
-
243
- var visibleActionReset = actionVisible && (values.ampm !== DEFAULT_VALUE && values.ampm != null || values.hours !== DEFAULT_VALUE || values.minutes !== DEFAULT_VALUE);
261
+ var visibleActionReset = actionVisible && (internalValue.ampm !== DEFAULT_VALUE && internalValue.ampm != null || internalValue.hours !== DEFAULT_VALUE || internalValue.minutes !== DEFAULT_VALUE);
244
262
  return /*#__PURE__*/_react.default.createElement("div", {
245
263
  className: "clay-time"
246
264
  }, /*#__PURE__*/_react.default.createElement(_form.ClayInput.Group, null, icon && /*#__PURE__*/_react.default.createElement(_form.ClayInput.GroupItem, {
@@ -282,11 +300,11 @@ var ClayTimePicker = function ClayTimePicker(_ref) {
282
300
  return handleInputFocus(TimeType.hours);
283
301
  },
284
302
  onKeyDown: function onKeyDown(event) {
285
- return handleKeyDown(event, values.hours, TimeType.hours);
303
+ return handleKeyDown(event, internalValue.hours, TimeType.hours);
286
304
  },
287
305
  readOnly: true,
288
306
  type: "text",
289
- value: values.hours
307
+ value: internalValue.hours
290
308
  }), /*#__PURE__*/_react.default.createElement("span", {
291
309
  className: "clay-time-divider"
292
310
  }, ":"), /*#__PURE__*/_react.default.createElement("input", {
@@ -300,11 +318,11 @@ var ClayTimePicker = function ClayTimePicker(_ref) {
300
318
  return handleInputFocus(TimeType.minutes);
301
319
  },
302
320
  onKeyDown: function onKeyDown(event) {
303
- return handleKeyDown(event, values.minutes, TimeType.minutes);
321
+ return handleKeyDown(event, internalValue.minutes, TimeType.minutes);
304
322
  },
305
323
  readOnly: true,
306
324
  type: "text",
307
- value: values.minutes
325
+ value: internalValue.minutes
308
326
  }), use12Hours && /*#__PURE__*/_react.default.createElement("input", {
309
327
  "aria-label": ariaLabels.ampm,
310
328
  className: (0, _classnames.default)('clay-time-ampm form-control-inset', {
@@ -316,15 +334,15 @@ var ClayTimePicker = function ClayTimePicker(_ref) {
316
334
  return handleInputFocus(TimeType.ampm);
317
335
  },
318
336
  onKeyDown: function onKeyDown(event) {
319
- return handleKeyDown(event, values.ampm, TimeType.ampm);
337
+ return handleKeyDown(event, internalValue.ampm, TimeType.ampm);
320
338
  },
321
339
  readOnly: true,
322
340
  type: "text",
323
- value: values.ampm || DEFAULT_VALUE
341
+ value: internalValue.ampm || DEFAULT_VALUE
324
342
  }), name && /*#__PURE__*/_react.default.createElement("input", {
325
343
  name: name,
326
344
  type: "hidden",
327
- value: "".concat(values.hours, ":").concat(values.minutes)
345
+ value: "".concat(internalValue.hours, ":").concat(internalValue.minutes)
328
346
  })), /*#__PURE__*/_react.default.createElement("div", {
329
347
  className: "clay-time-action-group"
330
348
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -339,7 +357,7 @@ var ClayTimePicker = function ClayTimePicker(_ref) {
339
357
  disabled: disabled,
340
358
  displayType: "unstyled",
341
359
  onClick: function onClick() {
342
- return onInputChange(use12Hours ? {
360
+ return setValue(use12Hours ? {
343
361
  ampm: DEFAULT_VALUE,
344
362
  hours: DEFAULT_VALUE,
345
363
  minutes: DEFAULT_VALUE
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clayui/time-picker",
3
- "version": "3.52.0",
3
+ "version": "3.55.0",
4
4
  "description": "ClayTimePicker component",
5
5
  "license": "BSD-3-Clause",
6
6
  "repository": "https://github.com/liferay/clay",
@@ -23,9 +23,9 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "@clayui/button": "^3.40.0",
26
- "@clayui/form": "^3.52.0",
26
+ "@clayui/form": "^3.55.0",
27
27
  "@clayui/icon": "^3.40.0",
28
- "@clayui/shared": "^3.52.0",
28
+ "@clayui/shared": "^3.55.0",
29
29
  "classnames": "^2.2.6"
30
30
  },
31
31
  "peerDependencies": {
@@ -36,5 +36,5 @@
36
36
  "browserslist": [
37
37
  "extends browserslist-config-clay"
38
38
  ],
39
- "gitHead": "eb7c98d6c746294376f10554c68cc48c30d8bd0e"
39
+ "gitHead": "5310f4650d453a3659b0bc73a5f098732168c9c1"
40
40
  }
package/src/index.tsx CHANGED
@@ -6,9 +6,9 @@
6
6
  import ClayButton from '@clayui/button';
7
7
  import {ClayInput} from '@clayui/form';
8
8
  import ClayIcon from '@clayui/icon';
9
- import {FocusScope} from '@clayui/shared';
9
+ import {FocusScope, InternalDispatch, useInternalState} from '@clayui/shared';
10
10
  import classNames from 'classnames';
11
- import React from 'react';
11
+ import React, {useEffect, useRef, useState} from 'react';
12
12
 
13
13
  type ConfigMaxMin = {
14
14
  max: number;
@@ -40,7 +40,11 @@ enum TimeType {
40
40
  ampm = 'ampm',
41
41
  }
42
42
 
43
- interface IProps extends React.HTMLAttributes<HTMLDivElement> {
43
+ interface IProps
44
+ extends Omit<
45
+ React.HTMLAttributes<HTMLDivElement>,
46
+ 'onChange' | 'defaultValue'
47
+ > {
44
48
  /**
45
49
  * Add the labels for the input elements and the input clear button,
46
50
  * use this to provide accessibility and internationalization.
@@ -68,25 +72,31 @@ interface IProps extends React.HTMLAttributes<HTMLDivElement> {
68
72
  */
69
73
  disabled?: boolean;
70
74
 
75
+ /**
76
+ * Property to set the default value (uncontrolled).
77
+ */
78
+ defaultValue?: Input;
79
+
71
80
  /**
72
81
  * Flag to indicate if show time icon or not.
73
82
  */
74
83
  icon?: boolean;
75
84
 
76
85
  /**
77
- * Called when input values change hour, minutes or ampm.
86
+ * Called when input values change hour, minutes or ampm (controlled).
78
87
  */
79
- onInputChange: (values: Input) => void;
88
+ onChange?: InternalDispatch<Input>;
80
89
 
81
90
  /**
82
- * Name attribute for the hidden input (used for form submission).
91
+ * Called when input values change hour, minutes or ampm (controlled).
92
+ * @deprecated since v3.52.0 - use `onChange` instead.
83
93
  */
84
- name?: string;
94
+ onInputChange?: InternalDispatch<Input>;
85
95
 
86
96
  /**
87
- * Sets the values for the hour, minute, or am/pm input.
97
+ * Name attribute for the hidden input (used for form submission).
88
98
  */
89
- values: Input;
99
+ name?: string;
90
100
 
91
101
  /**
92
102
  * The path to the SVG spritemap file containing the icons.
@@ -102,6 +112,17 @@ interface IProps extends React.HTMLAttributes<HTMLDivElement> {
102
112
  * Flag to indicate if 12-hour use, when true, should show am/pm input.
103
113
  */
104
114
  use12Hours?: boolean;
115
+
116
+ /**
117
+ * Sets the values for the hour, minute, or am/pm input (controlled).
118
+ * @deprecated since v3.52.0 - use `value` instead.
119
+ */
120
+ values?: Input;
121
+
122
+ /**
123
+ * Sets the values for the hour, minute, or am/pm input (controlled).
124
+ */
125
+ value?: Input;
105
126
  }
106
127
 
107
128
  const DEFAULT_VALUE = '--';
@@ -136,6 +157,8 @@ const DEFAULT_CONFIG = {
136
157
  },
137
158
  };
138
159
 
160
+ const regex = /^\d+$/;
161
+
139
162
  const ClayTimePicker: React.FunctionComponent<IProps> = ({
140
163
  ariaLabels = {
141
164
  ampm: 'Select time of day (AM/PM) using up (PM) and down (AM) arrow keys',
@@ -147,30 +170,44 @@ const ClayTimePicker: React.FunctionComponent<IProps> = ({
147
170
  },
148
171
  config = DEFAULT_CONFIG,
149
172
  disabled = false,
173
+ defaultValue = {
174
+ hours: DEFAULT_VALUE,
175
+ minutes: DEFAULT_VALUE,
176
+ },
150
177
  icon = false,
151
178
  name,
179
+ onChange,
180
+ onInputChange,
152
181
  spritemap,
153
182
  timezone,
154
183
  use12Hours = false,
155
- values = {
156
- hours: DEFAULT_VALUE,
157
- minutes: DEFAULT_VALUE,
158
- },
159
- onInputChange = () => {},
184
+ value,
185
+ values,
160
186
  }: IProps) => {
187
+ const [internalValue, setValue] = useInternalState({
188
+ defaultName: 'defaultValue',
189
+ defaultValue,
190
+ handleName: 'onChange',
191
+ name: 'value',
192
+ onChange: onChange ?? onInputChange,
193
+ value: value ?? values,
194
+ });
195
+
161
196
  const useConfig: Config = config[use12Hours ? 'use12Hours' : 'use24Hours'];
162
- const [actionVisible, setActionVisible] = React.useState(false);
163
- const [isFocused, setIsFocused] = React.useState(false);
164
- const elementRef = React.useRef<null | HTMLDivElement>(null);
197
+
198
+ const [actionVisible, setActionVisible] = useState(false);
199
+ const [isFocused, setIsFocused] = useState(false);
200
+ const elementRef = useRef<null | HTMLDivElement>(null);
201
+
165
202
  const defaultFocused = {
166
203
  configName: TimeType.hours,
167
204
  focused: false,
168
205
  };
169
- const [currentInputFocused, setCurrentInputFocused] = React.useState<{
206
+
207
+ const [currentInputFocused, setCurrentInputFocused] = useState<{
170
208
  configName: TimeType;
171
209
  focused: boolean;
172
210
  }>(defaultFocused);
173
- const regex = /^\d+$/;
174
211
 
175
212
  const handleMaxAndMin = (value: string, config: ConfigMaxMin) => {
176
213
  const newValue = value.substring(value.length - 2, value.length);
@@ -192,14 +229,14 @@ const ClayTimePicker: React.FunctionComponent<IProps> = ({
192
229
  ) => {
193
230
  const config = useConfig[configName];
194
231
  const intrinsicValue = Number(value);
195
- const setValue = (newValue: string | number) => {
232
+ const onValue = (newValue: string | number) => {
196
233
  const newVal =
197
234
  configName === TimeType.ampm
198
235
  ? newValue
199
236
  : handleMaxAndMin(String(newValue), config as ConfigMaxMin);
200
237
 
201
- return onInputChange({
202
- ...values,
238
+ return setValue({
239
+ ...internalValue,
203
240
  // eslint-disable-next-line sort-keys
204
241
  [configName]: String(newVal).padStart(2, '0'),
205
242
  });
@@ -207,16 +244,16 @@ const ClayTimePicker: React.FunctionComponent<IProps> = ({
207
244
 
208
245
  switch (event.key) {
209
246
  case 'Backspace':
210
- setValue(DEFAULT_VALUE);
247
+ onValue(DEFAULT_VALUE);
211
248
  break;
212
249
  case 'ArrowUp':
213
250
  event.preventDefault();
214
251
  event.stopPropagation();
215
252
 
216
253
  if (configName === TimeType.ampm) {
217
- setValue((config as ConfigAmpm).pm);
254
+ onValue((config as ConfigAmpm).pm);
218
255
  } else {
219
- setValue(
256
+ onValue(
220
257
  value !== DEFAULT_VALUE
221
258
  ? intrinsicValue + 1
222
259
  : (config as ConfigMaxMin).min
@@ -228,9 +265,9 @@ const ClayTimePicker: React.FunctionComponent<IProps> = ({
228
265
  event.stopPropagation();
229
266
 
230
267
  if (configName === TimeType.ampm) {
231
- setValue((config as ConfigAmpm).am);
268
+ onValue((config as ConfigAmpm).am);
232
269
  } else {
233
- setValue(
270
+ onValue(
234
271
  value !== DEFAULT_VALUE
235
272
  ? intrinsicValue - 1
236
273
  : (config as ConfigMaxMin).max
@@ -256,12 +293,12 @@ const ClayTimePicker: React.FunctionComponent<IProps> = ({
256
293
  : (value && value !== DEFAULT_VALUE ? value : '') +
257
294
  keyVal;
258
295
 
259
- setValue(newVal);
296
+ onValue(newVal);
260
297
  } else if (
261
298
  configName === TimeType.ampm &&
262
299
  (event.key === 'a' || event.key === 'p')
263
300
  ) {
264
- setValue(
301
+ onValue(
265
302
  event.key === 'a'
266
303
  ? (config as ConfigAmpm).am
267
304
  : (config as ConfigAmpm).pm
@@ -274,7 +311,7 @@ const ClayTimePicker: React.FunctionComponent<IProps> = ({
274
311
  const handleAction = (direction: number) => {
275
312
  const {configName} = currentInputFocused;
276
313
  const config = useConfig[configName];
277
- const prevValue = values[configName];
314
+ const prevValue = internalValue[configName];
278
315
  let value;
279
316
 
280
317
  if (configName === TimeType.ampm) {
@@ -299,8 +336,8 @@ const ClayTimePicker: React.FunctionComponent<IProps> = ({
299
336
  configName,
300
337
  focused: true,
301
338
  });
302
- onInputChange({
303
- ...values,
339
+ setValue({
340
+ ...internalValue,
304
341
  // eslint-disable-next-line sort-keys
305
342
  [configName]: String(value).padStart(2, '0'),
306
343
  });
@@ -327,7 +364,7 @@ const ClayTimePicker: React.FunctionComponent<IProps> = ({
327
364
  setIsFocused(true);
328
365
  };
329
366
 
330
- React.useEffect(() => {
367
+ useEffect(() => {
331
368
  document.addEventListener('click', handleDocumentClick);
332
369
 
333
370
  return () => {
@@ -337,9 +374,9 @@ const ClayTimePicker: React.FunctionComponent<IProps> = ({
337
374
 
338
375
  const visibleActionReset =
339
376
  actionVisible &&
340
- ((values.ampm !== DEFAULT_VALUE && values.ampm != null) ||
341
- values.hours !== DEFAULT_VALUE ||
342
- values.minutes !== DEFAULT_VALUE);
377
+ ((internalValue.ampm !== DEFAULT_VALUE && internalValue.ampm != null) ||
378
+ internalValue.hours !== DEFAULT_VALUE ||
379
+ internalValue.minutes !== DEFAULT_VALUE);
343
380
 
344
381
  return (
345
382
  <div className="clay-time">
@@ -392,13 +429,13 @@ const ClayTimePicker: React.FunctionComponent<IProps> = ({
392
429
  onKeyDown={(event) =>
393
430
  handleKeyDown(
394
431
  event,
395
- values.hours,
432
+ internalValue.hours,
396
433
  TimeType.hours
397
434
  )
398
435
  }
399
436
  readOnly
400
437
  type="text"
401
- value={values.hours}
438
+ value={internalValue.hours}
402
439
  />
403
440
  <span className="clay-time-divider">:</span>
404
441
  <input
@@ -420,13 +457,13 @@ const ClayTimePicker: React.FunctionComponent<IProps> = ({
420
457
  onKeyDown={(event) =>
421
458
  handleKeyDown(
422
459
  event,
423
- values.minutes,
460
+ internalValue.minutes,
424
461
  TimeType.minutes
425
462
  )
426
463
  }
427
464
  readOnly
428
465
  type="text"
429
- value={values.minutes}
466
+ value={internalValue.minutes}
430
467
  />
431
468
  {use12Hours && (
432
469
  <input
@@ -448,20 +485,22 @@ const ClayTimePicker: React.FunctionComponent<IProps> = ({
448
485
  onKeyDown={(event) =>
449
486
  handleKeyDown(
450
487
  event,
451
- values.ampm as InputAmPm,
488
+ internalValue.ampm as InputAmPm,
452
489
  TimeType.ampm
453
490
  )
454
491
  }
455
492
  readOnly
456
493
  type="text"
457
- value={values.ampm || DEFAULT_VALUE}
494
+ value={
495
+ internalValue.ampm || DEFAULT_VALUE
496
+ }
458
497
  />
459
498
  )}
460
499
  {name && (
461
500
  <input
462
501
  name={name}
463
502
  type="hidden"
464
- value={`${values.hours}:${values.minutes}`}
503
+ value={`${internalValue.hours}:${internalValue.minutes}`}
465
504
  />
466
505
  )}
467
506
  </div>
@@ -482,7 +521,7 @@ const ClayTimePicker: React.FunctionComponent<IProps> = ({
482
521
  disabled={disabled}
483
522
  displayType="unstyled"
484
523
  onClick={() =>
485
- onInputChange(
524
+ setValue(
486
525
  use12Hours
487
526
  ? {
488
527
  ampm: DEFAULT_VALUE,