-
Notifications
You must be signed in to change notification settings - Fork 38
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
[MDS-5801] Text/Language updates #2976
Changes from all commits
56c0135
6c74846
20a387f
8fe0505
b74bfb9
3f8d98f
b1b5dab
aaca7ff
c0b57da
db1ea5f
390a5d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React, { useState, useEffect, FC } from "react"; | ||
import React, { FC } from "react"; | ||
import { Input, Form, Row } from "antd"; | ||
import { BaseInputProps, BaseViewInput, getFormItemLabel } from "./BaseInput"; | ||
import { FormConsumer, IFormContext } from "./FormWrapper"; | ||
|
@@ -9,36 +9,19 @@ import { FormConsumer, IFormContext } from "./FormWrapper"; | |
|
||
interface AutoSizeProps extends BaseInputProps { | ||
minRows?: number; | ||
maximumCharacters?: number; | ||
maximumCharacters: number; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I decided that this should be mandatory. There's no instances where this version of the component (ie the one in common) is used and the value is not supplied. |
||
|
||
const RenderAutoSizeField: FC<AutoSizeProps> = ({ | ||
label = "", | ||
labelSubtitle, | ||
help, | ||
disabled = false, | ||
maximumCharacters = 0, | ||
maximumCharacters, | ||
minRows = 3, | ||
required = false, | ||
...props | ||
}) => { | ||
const [remainingChars, setRemainingChars] = useState(maximumCharacters); | ||
const [inputValue, setValue] = useState(props.input.value ?? ""); | ||
|
||
const handleTextAreaChange = (event) => { | ||
setValue(event.target.value); | ||
if (maximumCharacters > 0) { | ||
const input = event.target.value; | ||
const remaining = maximumCharacters - input.length; | ||
setRemainingChars(remaining); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
const input = props.input.value; | ||
const remaining = maximumCharacters - input.length; | ||
setRemainingChars(remaining); | ||
}, []); | ||
|
||
return ( | ||
<FormConsumer> | ||
{(value: IFormContext) => { | ||
|
@@ -68,15 +51,19 @@ const RenderAutoSizeField: FC<AutoSizeProps> = ({ | |
{...props.input} | ||
autoSize={{ minRows: minRows }} | ||
placeholder={props.placeholder} | ||
onChange={handleTextAreaChange} | ||
value={inputValue} | ||
/> | ||
{maximumCharacters > 0 && ( | ||
<Row justify="space-between"> | ||
<Row | ||
justify="space-between" | ||
className={`form-item-help ${props.input.name}-form-help`} | ||
> | ||
{help ? ( | ||
<span>{help}</span> | ||
) : ( | ||
<span>{`Maximum ${maximumCharacters} characters`}</span> | ||
<span className="flex-end">{`${remainingChars} / ${maximumCharacters}`}</span> | ||
</Row> | ||
)} | ||
)} | ||
<span className="flex-end">{`${maximumCharacters - | ||
props.input.value.length} / ${maximumCharacters}`}</span> | ||
</Row> | ||
</> | ||
</Form.Item> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ interface SelectProps extends BaseInputProps { | |
|
||
export const RenderSelect: FC<SelectProps> = ({ | ||
label = "", | ||
labelSubtitle, | ||
id, | ||
meta, | ||
input, | ||
|
@@ -45,7 +46,7 @@ export const RenderSelect: FC<SelectProps> = ({ | |
return ( | ||
<Form.Item | ||
name={input.name} | ||
label={getFormItemLabel(label, required)} | ||
label={getFormItemLabel(label, required, labelSubtitle)} | ||
required={required} | ||
validateStatus={ | ||
isDirty || meta.touched ? (meta.error && "error") || (meta.warning && "warning") : "" | ||
|
@@ -56,7 +57,7 @@ export const RenderSelect: FC<SelectProps> = ({ | |
(meta.warning && <span>{meta.warning}</span>)) | ||
} | ||
id={id} | ||
getValueProps={() => ({ value: input.value })} | ||
getValueProps={() => input.value !== "" && { value: input.value }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. placeholder wasn't showing because I think redux was supplying it with "" when it was empty. |
||
> | ||
<Select | ||
virtual={false} | ||
|
@@ -70,7 +71,6 @@ export const RenderSelect: FC<SelectProps> = ({ | |
optionFilterProp="children" | ||
filterOption={caseInsensitiveLabelFilter} | ||
id={id} | ||
value={data.length && input.value ? input.value : null} | ||
onChange={(changeValue) => { | ||
setIsDirty(true); | ||
input.onChange(changeValue); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty much just updating this file to accept elements as well as strings for labels.