Skip to content

Commit 37a97a4

Browse files
Fixes on Required field when empty label and DatepickerInput selector (#159)
Two fixes: 1- star not visible on required field label when the label is empty 2- Ids can start as numbers in HTML5 (hence guid as id is okay), but querySelector uses CSS3 selectors for querying the DOM and CSS3 doesn't support ID selectors that start with a digit
1 parent 0e34721 commit 37a97a4

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fix
11+
12+
- `*` visibility on a required field label, whether the label is empty.
13+
- `DatePickerInput` selector when `onClickOutside` function is triggered.
14+
1015
## [3.15.0] - 2025-12-19
1116

1217
### Added

src/lib/DatePickerInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ const DatePickerInput = <T extends FieldValues>(props: DatePickerInputProps<T>)
181181
field.onChange(convertedDate);
182182
}}
183183
onClickOutside={(e) => {
184-
if (document.querySelector(`#${formGroupId.current}`)?.contains(e.target as HTMLElement) && !disabled && !formDisabled) {
184+
if (document.getElementById(formGroupId.current)?.contains(e.target as HTMLElement) && !disabled && !formDisabled) {
185185
internalDatePickerRef.current?.setOpen(true);
186186
}
187187

src/lib/helpers/form.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ReactNode } from "react";
22
import { FieldPath, FieldValues } from "react-hook-form";
33
import { RequiredFieldPath } from "../types/Form";
4+
import { isNullOrWhitespace } from "@neolution-ch/javascript-utils";
45

56
const matchesWildcard = (rule: string, pathParts: string[]) => {
67
const ruleParts = rule.split(".");
@@ -20,6 +21,7 @@ const getRequiredLabel = <T extends FieldValues>(
2021
label: ReactNode,
2122
fieldPath: FieldPath<T>,
2223
requiredFields?: RequiredFieldPath<T>[],
23-
): ReactNode => (typeof label === "string" ? (isRequiredField(fieldPath, requiredFields) ? `${String(label)} *` : label) : label);
24+
): ReactNode =>
25+
typeof label === "string" && !isNullOrWhitespace(label) && isRequiredField(fieldPath, requiredFields) ? `${label} *` : label;
2426

2527
export { getRequiredLabel, isRequiredField };

0 commit comments

Comments
 (0)