@@ -2,10 +2,11 @@ import React, { useCallback, useState } from 'react'
22import ClassNames from 'classnames'
33import Form from 'react-bootstrap/Form'
44
5- interface IIntInputControlProps {
5+ interface ITimeMsInputControlProps {
66 classNames ?: string
77 modifiedClassName ?: string
88 disabled ?: boolean
9+ readOnly ?: boolean
910 placeholder ?: string
1011
1112 /** Call handleUpdate on every change, before focus is lost */
@@ -89,13 +90,14 @@ export function TimeMsInputControl({
8990 modifiedClassName,
9091 value,
9192 disabled,
93+ readOnly,
9294 placeholder,
9395 handleUpdate,
9496 updateOnKey,
9597 min,
9698 max,
9799 multipleOf,
98- } : Readonly < IIntInputControlProps > ) : JSX . Element {
100+ } : Readonly < ITimeMsInputControlProps > ) : JSX . Element {
99101 const [ editingValue , setEditingValue ] = useState < string | null > ( null )
100102
101103 const isValidValue = useCallback ( ( value : number ) : boolean => {
@@ -108,25 +110,28 @@ export function TimeMsInputControl({
108110
109111 const handleChange = useCallback (
110112 ( event : React . ChangeEvent < HTMLInputElement > ) => {
113+ if ( readOnly ) return
114+
111115 const number = parseTime ( event . target . value )
112116 setEditingValue ( event . target . value )
113117
114118 if ( updateOnKey && ! isNaN ( number ) && isValidValue ( number ) ) {
115119 handleUpdate ( number )
116120 }
117121 } ,
118- [ handleUpdate , updateOnKey , isValidValue ]
122+ [ handleUpdate , updateOnKey , isValidValue , readOnly ]
119123 )
120124 const handleBlur = useCallback (
121125 ( event : React . FocusEvent < HTMLInputElement > ) => {
126+ if ( readOnly ) return
122127 const number = parseTime ( event . currentTarget . value )
123128 if ( ! isNaN ( number ) && isValidValue ( number ) ) {
124129 handleUpdate ( number )
125130 }
126131
127132 setEditingValue ( null )
128133 } ,
129- [ handleUpdate , isValidValue ]
134+ [ handleUpdate , isValidValue , readOnly ]
130135 )
131136 const handleFocus = useCallback ( ( event : React . FocusEvent < HTMLInputElement > ) => {
132137 setEditingValue ( event . currentTarget . value )
@@ -135,6 +140,8 @@ export function TimeMsInputControl({
135140 } , [ ] )
136141 const handleKeyUp = useCallback (
137142 ( event : React . KeyboardEvent < HTMLInputElement > ) => {
143+ if ( readOnly ) return
144+
138145 if ( event . key === 'Escape' ) {
139146 setEditingValue ( null )
140147 } else if ( event . key === 'Enter' ) {
@@ -144,7 +151,7 @@ export function TimeMsInputControl({
144151 }
145152 }
146153 } ,
147- [ handleUpdate , isValidValue ]
154+ [ handleUpdate , isValidValue , readOnly ]
148155 )
149156 const handleKeyDown = useCallback ( ( event : React . KeyboardEvent < HTMLInputElement > ) => {
150157 // allow ctrl/cmd + any key, to allow for shortcuts like ctrl+a, ctrl+c, ctrl+v, etc.
@@ -170,6 +177,7 @@ export function TimeMsInputControl({
170177 onFocus = { handleFocus }
171178 onKeyUp = { handleKeyUp }
172179 onKeyDown = { handleKeyDown }
180+ readOnly = { readOnly }
173181 disabled = { disabled }
174182 />
175183 )
0 commit comments