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

Adding of clear and cancel button in create preset form #8921

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/CameraFeed/ConfigureCamera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,22 @@ export default function ConfigureCamera(props: Props) {
>
<TextFormField
name="preset-name"
className="py-4"
className="w-full py-4"
value={presetName}
onChange={({ value }) => setPresetName(value)}
errorClassName="hidden"
placeholder={t("preset_name_placeholder")}
suggestions={presetNameSuggestions}
clearable={true}
/>

<div className="cui-form-button-group">
<Cancel
onClick={() => {
setCreatePreset(undefined);
setPresetName("");
}}
/>
<Submit
onClick={async () => {
const { res } = await request(FeedRoutes.createPreset, {
Expand Down
47 changes: 30 additions & 17 deletions src/components/Form/FormFields/TextFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type TextFormFieldProps = FormFieldBaseProps<string> &
trailingPadding?: string | undefined;
leadingPadding?: string | undefined;
suggestions?: string[];
clearable?: boolean | undefined;
};

const TextFormField = forwardRef((props: TextFormFieldProps, ref) => {
Expand All @@ -41,24 +42,36 @@ const TextFormField = forwardRef((props: TextFormFieldProps, ref) => {
};

let child = (
<input
{...props}
ref={ref as React.Ref<HTMLInputElement>}
id={field.id}
className={classNames(
"cui-input-base peer",
hasLeading && (props.leadingPadding || "pl-10"),
hasTrailing && (props.trailingPadding || "pr-10"),
field.error && "border-danger-500",
props.inputClassName,
<div className="relative">
<input
{...props}
ref={ref as React.Ref<HTMLInputElement>}
id={field.id}
className={classNames(
"cui-input-base peer",
hasLeading && (props.leadingPadding || "pl-10"),
hasTrailing && (props.trailingPadding || "pr-10"),
field.error && "border-danger-500",
props.inputClassName,
)}
disabled={field.disabled}
type={props.type === "password" ? getPasswordFieldType() : props.type}
name={field.name}
value={field.value}
required={field.required}
onChange={(e) => field.handleChange(e.target.value)}
/>
{props.clearable && field.value && (
<button
type="button"
className="absolute right-2 top-1/2 -translate-y-1/2 transform text-gray-500"
onClick={() => field.handleChange("")}
aria-label="Clear input"
>
<CareIcon icon="l-times-circle" className="text-lg" />
</button>
)}
disabled={field.disabled}
type={props.type === "password" ? getPasswordFieldType() : props.type}
name={field.name}
value={field.value}
required={field.required}
onChange={(e) => field.handleChange(e.target.value)}
/>
</div>
);

if (props.type === "password") {
Expand Down
Loading