Skip to content

Commit

Permalink
fix(InputField,Textarea): stop bubbling for processed arrow key events
Browse files Browse the repository at this point in the history
  • Loading branch information
CoroDaniel authored and cipak committed Mar 28, 2022
1 parent bf5d4b8 commit 0c46a27
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={true}
tabIndex={0}
type="text"
Expand Down Expand Up @@ -244,6 +245,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={true}
tabIndex={0}
type="text"
Expand Down Expand Up @@ -300,6 +302,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={true}
tabIndex={0}
type="email"
Expand Down Expand Up @@ -422,6 +425,7 @@ Array [
max={10}
min={1}
onChange={[Function]}
onKeyDown={[Function]}
placeholder="Please select the number of guests"
required={true}
tabIndex={0}
Expand Down Expand Up @@ -595,6 +599,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={true}
tabIndex={0}
type="date"
Expand Down Expand Up @@ -662,6 +667,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={true}
tabIndex={0}
type="time"
Expand Down Expand Up @@ -714,6 +720,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={true}
tabIndex={0}
type="date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Array [
id="wxc-0-control"
name="name"
onChange={[Function]}
onKeyDown={[Function]}
required={false}
tabIndex={101}
type="text"
Expand Down Expand Up @@ -96,6 +97,7 @@ Array [
id="wxc-0-control"
name="password"
onChange={[Function]}
onKeyDown={[Function]}
required={false}
tabIndex={102}
type="password"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Array [
id="wxc-0-control"
name="password"
onChange={[Function]}
onKeyDown={[Function]}
required={false}
tabIndex={101}
type="password"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={false}
tabIndex={0}
type="text"
Expand Down Expand Up @@ -128,6 +129,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={false}
tabIndex={0}
type="text"
Expand Down Expand Up @@ -521,6 +523,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
placeholder="What is your first name?"
required={true}
tabIndex={0}
Expand Down Expand Up @@ -560,6 +563,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
placeholder="What is your last name?"
required={false}
tabIndex={0}
Expand Down Expand Up @@ -598,6 +602,7 @@ Array [
max={10}
min={1}
onChange={[Function]}
onKeyDown={[Function]}
placeholder="Enter a number between 1 and 10"
required={false}
tabIndex={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={false}
tabIndex={0}
type="date"
Expand Down Expand Up @@ -695,6 +696,7 @@ Array [
max={10}
min={1}
onChange={[Function]}
onKeyDown={[Function]}
placeholder="Enter a number"
required={false}
tabIndex={0}
Expand Down Expand Up @@ -914,6 +916,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={true}
tabIndex={0}
type="text"
Expand Down Expand Up @@ -985,6 +988,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={false}
tabIndex={0}
type="email"
Expand Down Expand Up @@ -1034,6 +1038,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={false}
tabIndex={0}
type="tel"
Expand Down Expand Up @@ -1083,6 +1088,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={false}
tabIndex={0}
type="url"
Expand Down Expand Up @@ -1132,6 +1138,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={false}
tabIndex={0}
type="password"
Expand Down Expand Up @@ -1192,6 +1199,7 @@ Array [
id="wxc-0-control"
maxLength={500}
onChange={[Function]}
onKeyDown={[Function]}
placeholder="enter comment"
rows={5}
value=""
Expand Down Expand Up @@ -1250,6 +1258,7 @@ Array [
id="wxc-0-control"
maxLength={500}
onChange={[Function]}
onKeyDown={[Function]}
placeholder="enter comment"
rows={5}
value="This value was pre-filled"
Expand Down Expand Up @@ -1355,6 +1364,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={false}
tabIndex={0}
type="time"
Expand Down Expand Up @@ -1405,6 +1415,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={true}
tabIndex={0}
type="time"
Expand Down Expand Up @@ -1450,6 +1461,7 @@ Array [
disabled={false}
id="wxc-0-control"
onChange={[Function]}
onKeyDown={[Function]}
required={false}
tabIndex={0}
type="time"
Expand Down
9 changes: 9 additions & 0 deletions src/components/generic/InputField/InputField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ export default function InputField({
const handleChange = (event) => onChange(event.target.value);
const id = domId || uniqueId();

const onKeyDown = (event) => {
const keys = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];

if (keys.includes(event.key)) {
event.stopPropagation(); // prevent other navigation
}
};

useAutoFocus(inputRef, autoFocus);

return (
Expand Down Expand Up @@ -94,6 +102,7 @@ export default function InputField({
min={min}
name={name}
onChange={handleChange}
onKeyDown={onKeyDown}
pattern={pattern}
placeholder={placeholder}
ref={inputRef}
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/NumberInput/NumberInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ NumberInput.propTypes = {
required: PropTypes.bool,
style: PropTypes.shape(),
tabIndex: PropTypes.number,
value: PropTypes.oneOf([
value: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
]),
Expand Down
9 changes: 9 additions & 0 deletions src/components/inputs/Textbox/Textbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ export default function Textbox({
const [cssClasses, sc] = webexComponentClasses('textbox', className);
const id = domId || uniqueId();

const onKeyDown = (event) => {
const keys = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];

if (keys.includes(event.key)) {
event.stopPropagation(); // prevent other navigation
}
};

return (
<Label
className={cssClasses}
Expand All @@ -59,6 +67,7 @@ export default function Textbox({
maxLength={maxLength}
name={name}
onChange={(event) => onChange(event.target.value)}
onKeyDown={onKeyDown}
placeholder={placeholder}
rows={5}
value={value}
Expand Down

0 comments on commit 0c46a27

Please sign in to comment.