Skip to content

Commit

Permalink
fix(RequiredIndicator): display as asterisk instead of text
Browse files Browse the repository at this point in the history
  • Loading branch information
MiroslavPetrik committed Nov 28, 2023
1 parent f65b78a commit 8a58926
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/components/field/FlowbiteField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { RenderProp } from "react-render-prop-type";

import { FlowbiteStateColor, useFieldError } from "../../hooks";
import { useAtomValue } from "jotai";
import { RequiredIndicator } from "@/components";

type Children = RenderProp<
Omit<RequiredProps, "isFieldRequired"> & {
Expand Down Expand Up @@ -41,7 +42,8 @@ export const FlowbiteField = <Field extends ZodField<any, any>>({
<div className="flex flex-col gap-2">
{label && (
<Label color={color} htmlFor={id}>
{label} {isFieldRequired ? "(required)" : ""}
<span>{label}</span>
{isFieldRequired ? <RequiredIndicator /> : ""}
</Label>
)}
{children({ ...requiredProps, id, helperText, color })}
Expand Down
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from "./file-field";
export * from "./number-field";
export * from "./radio-field";
export * from "./rating-field";
export * from "./required-indicator";
export * from "./select-field";
export * from "./slider-field";
export * from "./text-field";
Expand Down
6 changes: 5 additions & 1 deletion src/components/radio-option/RadioOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { HelperText, Label, Radio } from "flowbite-react";

import { useFieldError } from "../../hooks";
import { useAtomValue } from "jotai";
import { RequiredIndicator } from "@/components";

export const RadioOption = <Field extends CheckboxField>({
field,
Expand All @@ -27,7 +28,10 @@ export const RadioOption = <Field extends CheckboxField>({
<Radio {...props} id={id} {...requiredProps} role="radio" />
<div className="flex flex-col">
<Label htmlFor={id} color={error ? "failure" : undefined}>
{label} {isFieldRequired ? "(required)" : ""}
<>
{label}
{isFieldRequired ? <RequiredIndicator /> : ""}
</>
</Label>
<HelperText
className="mt-0 text-xs"
Expand Down
5 changes: 5 additions & 0 deletions src/components/required-indicator/RequiredIndicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const RequiredIndicator = () => (
<span role="presentation" aria-hidden="true" className="ms-1 text-red-500">
*
</span>
);
1 change: 1 addition & 0 deletions src/components/required-indicator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./RequiredIndicator";

0 comments on commit 8a58926

Please sign in to comment.