Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Duplicate ids associate labels with bad checkbox inputs #2405

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions frontend-html/src/gui/Components/Form/CheckBox.tsx
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
Expand Up @@ -72,7 +72,6 @@ export const MobileCheckBox: React.FC<{
return (
<div>
<label
htmlFor={props.property!.modelInstanceId}
style={captionStyle()}
>
{label}
Expand Down