Skip to content

Commit

Permalink
FIX: Duplicate ids associate labels with bad checkbox inputs (#2394)
Browse files Browse the repository at this point in the history
Co-authored-by: Pavel Tomasko <ptomasko@purple-technology.com>
  • Loading branch information
ptomask and ptomasko committed Jan 16, 2024
1 parent 8f5a2bb commit 447674c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 5 additions & 3 deletions frontend-html/src/gui/Components/Form/CheckBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with ORIGAM. If not, see <http://www.gnu.org/licenses/>.
*/

import React, { useState } from "react";
import React, { useMemo, useState } from "react";
import { IProperty } from "model/entities/types/IProperty";
import { BoolEditor } from "gui/Components/ScreenElements/Editors/BoolEditor";
import S from "gui/Components/Form/CheckBox.module.scss";
Expand All @@ -27,6 +27,7 @@ import { onFieldBlur } from "model/actions-ui/DataView/TableView/onFieldBlur";
import { onFieldChange } from "model/actions-ui/DataView/TableView/onFieldChange";
import { IFocusable } from "model/entities/FormFocusManager";
import { FieldDimensions } from "gui/Components/Form/FieldDimensions";
import * as uuid from 'uuid';

export const CheckBox: React.FC<{
checked: boolean;
Expand All @@ -52,6 +53,7 @@ export const CheckBox: React.FC<{
}),
};
})((props) => {
const labelId = useMemo(() => uuid.v4(), []);
const [isFocused, setIsFocused] = useState<boolean>(false);

const label = props.property!.name;
Expand Down Expand Up @@ -103,7 +105,7 @@ export const CheckBox: React.FC<{
<div>
<div className={S.editor} style={formFieldStyle()}>
<BoolEditor
id={props.property!.modelInstanceId}
id={labelId}
value={props.checked}
isReadOnly={props.readOnly}
onBlur={onInputBlur}
Expand All @@ -115,7 +117,7 @@ export const CheckBox: React.FC<{
/>
</div>
<label
htmlFor={props.property!.modelInstanceId}
htmlFor={labelId}
className={S.caption + " " + (isFocused ? S.focusedLabel : S.unFocusedLabel)}
style={captionStyle()}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export const MobileCheckBox: React.FC<{
return (
<div>
<label
htmlFor={props.property!.modelInstanceId}
style={captionStyle()}
>
{label}
Expand Down

0 comments on commit 447674c

Please sign in to comment.