From db5491a8fdcbd4a0c33e4d0682c1b8dcbb149fe1 Mon Sep 17 00:00:00 2001 From: CD Cabrera Date: Tue, 26 Jan 2021 17:17:27 -0500 Subject: [PATCH] fix(checkbox,textInput): consistent name, id attributes (#564) --- .../__snapshots__/textInput.test.js.snap | 4 ++++ src/components/form/checkbox.js | 23 +++++++++++-------- src/components/form/textInput.js | 21 ++++++++++------- .../toolbarFieldDisplayName.test.js.snap | 1 + 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/components/form/__tests__/__snapshots__/textInput.test.js.snap b/src/components/form/__tests__/__snapshots__/textInput.test.js.snap index 75a0a7af7..38a3a0704 100644 --- a/src/components/form/__tests__/__snapshots__/textInput.test.js.snap +++ b/src/components/form/__tests__/__snapshots__/textInput.test.js.snap @@ -5,6 +5,7 @@ exports[`TextInput Component should handle readOnly, disabled: active 1`] = ` aria-invalid="false" class="pf-c-form-control curiosity-text-input " id="generatedid-" + name="generatedid-" type="text" value="" /> @@ -16,6 +17,7 @@ exports[`TextInput Component should handle readOnly, disabled: disabled 1`] = ` class="pf-c-form-control curiosity-text-input " disabled="" id="generatedid-" + name="generatedid-" type="text" value="" /> @@ -26,6 +28,7 @@ exports[`TextInput Component should handle readOnly, disabled: readOnly 1`] = ` aria-invalid="false" class="pf-c-form-control curiosity-text-input " id="generatedid-" + name="generatedid-" readonly="" type="text" value="" @@ -37,6 +40,7 @@ exports[`TextInput Component should render a basic component: basic component 1` aria-invalid="false" class="pf-c-form-control curiosity-text-input " id="generatedid-" + name="generatedid-" type="text" value="" /> diff --git a/src/components/form/checkbox.js b/src/components/form/checkbox.js index 4b99df322..79a287058 100644 --- a/src/components/form/checkbox.js +++ b/src/components/form/checkbox.js @@ -11,6 +11,7 @@ import { helpers } from '../../common'; * @param {object} props * @param {string} props.ariaLabel * @param {Node} props.children + * @param {string} props.id * @param {*} props.isChecked * @param {boolean} props.isDisabled * @param {boolean} props.isReadOnly @@ -23,6 +24,7 @@ import { helpers } from '../../common'; const Checkbox = ({ ariaLabel, children, + id, isChecked, isDisabled, isReadOnly, @@ -34,7 +36,8 @@ const Checkbox = ({ }) => { const [check, setCheck] = React.useState(); const updatedChecked = check ?? isChecked ?? false; - const nameId = name || helpers.generateId(); + const updatedName = name || helpers.generateId(); + const updatedId = id || updatedName; /** * onChange event, provide restructured event. @@ -46,8 +49,8 @@ const Checkbox = ({ const onCheckboxChange = (checked, event) => { const mockEvent = { ...createMockEvent(event), - id: nameId, - name: nameId, + id: updatedId, + name: updatedName, value, checked }; @@ -60,11 +63,11 @@ const Checkbox = ({