Skip to content

Commit 6a8828a

Browse files
committed
Improve BM description character limit UX
1 parent 9f49bd4 commit 6a8828a

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

src/components/BMDashboard/Equipment/Add/AddTypeForm.jsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ const FuelTypes = {
1515
etha: 'Ethanol',
1616
};
1717

18+
const DESC_CHAR_LIMIT = 150;
19+
1820
// const [inputText, setInputText] = useState('');
1921

2022
const schema = Joi.object({
2123
name: Joi.string().required(),
2224
desc: Joi.string()
2325
.required()
24-
.max(150),
26+
.max(DESC_CHAR_LIMIT),
2527
});
2628

2729
export default function AddTypeForm() {
@@ -46,7 +48,7 @@ export default function AddTypeForm() {
4648
setName(event.target.value);
4749
}
4850
if (event.target.name === 'desc') {
49-
setDesc(event.target.value);
51+
setDesc(event.target.value.slice(0, DESC_CHAR_LIMIT));
5052
}
5153
if (event.target.name === 'fuel') {
5254
setFuel(event.target.value);
@@ -104,12 +106,24 @@ export default function AddTypeForm() {
104106
name="desc"
105107
type="textarea"
106108
rows={2}
109+
maxLength={DESC_CHAR_LIMIT}
107110
value={desc}
108111
invalid={errInput === 'desc'}
109112
onChange={handleChange}
110113
/>
111-
<div className="form-footer" style={{ color: desc.length > 150 ? '#dc3545' : 'black' }}>
112-
Character {desc.length}/150
114+
<div
115+
className="form-footer"
116+
style={{
117+
display: 'flex',
118+
justifyContent: 'space-between',
119+
gap: '1rem',
120+
color: 'black',
121+
}}
122+
>
123+
<span>
124+
Character {desc.length}/{DESC_CHAR_LIMIT}
125+
</span>
126+
<span aria-live="polite">{DESC_CHAR_LIMIT - desc.length} characters left</span>
113127
</div>
114128
{/* {!errInput && <FormText>Max 150 characters</FormText>} */}
115129
<FormFeedback>

src/components/BMDashboard/EquipmentPurchaseRequest/PurchaseForm.jsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { purchaseEquipment } from '~/actions/bmdashboard/equipmentActions';
1010

1111
import stylesPurchaseForm from './PurchaseForm.module.css';
1212

13+
const DESC_CHAR_LIMIT = 150;
14+
1315
export default function PurchaseForm() {
1416
const bmProjects = useSelector(state => state.bmProjects);
1517
const equipments = useSelector(state => state.bmInvTypes.list);
@@ -38,7 +40,7 @@ export default function PurchaseForm() {
3840
estTime: Joi.string().required(),
3941
desc: Joi.string()
4042
.required()
41-
.max(150),
43+
.max(DESC_CHAR_LIMIT),
4244
makeModel: Joi.string().allow(''),
4345
});
4446

@@ -204,13 +206,23 @@ export default function PurchaseForm() {
204206
<Input
205207
id="input-usage-description"
206208
type="textarea"
209+
maxLength={DESC_CHAR_LIMIT}
207210
value={desc}
208211
onChange={({ currentTarget }) => {
209212
setValidationError('');
210-
setDesc(currentTarget.value);
213+
setDesc(currentTarget.value.slice(0, DESC_CHAR_LIMIT));
211214
}}
212215
/>
213-
<FormText>Max 150 characters</FormText>
216+
<FormText
217+
style={{
218+
display: 'flex',
219+
justifyContent: 'space-between',
220+
gap: '1rem',
221+
}}
222+
>
223+
<span>Max {DESC_CHAR_LIMIT} characters</span>
224+
<span aria-live="polite">{DESC_CHAR_LIMIT - desc.length} characters left</span>
225+
</FormText>
214226
</FormGroup>
215227
<FormGroup>
216228
<Label for="input-brand">Preferred Make &amp; Model (optional)</Label>

src/components/BMDashboard/ToolPurchaseRequest/PurchaseForm.jsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import styles from './PurchaseForm.module.css';
1212

1313
const PRIORITY_ORDER = { Low: 1, Medium: 2, High: 3 };
1414
const RECENT_REQUEST_WINDOW_DAYS = 30;
15+
const DESC_CHAR_LIMIT = 150;
1516

1617
function getObjectId(value) {
1718
if (!value) return '';
@@ -115,7 +116,7 @@ export default function PurchaseForm() {
115116
estTime: Joi.string().required(),
116117
desc: Joi.string()
117118
.required()
118-
.max(150),
119+
.max(DESC_CHAR_LIMIT),
119120
makeModel: Joi.string().allow(''),
120121
});
121122

@@ -425,13 +426,23 @@ export default function PurchaseForm() {
425426
<Input
426427
id="input-usage-description"
427428
type="textarea"
429+
maxLength={DESC_CHAR_LIMIT}
428430
value={desc}
429431
onChange={({ currentTarget }) => {
430432
setValidationError('');
431-
setDesc(currentTarget.value);
433+
setDesc(currentTarget.value.slice(0, DESC_CHAR_LIMIT));
432434
}}
433435
/>
434-
<FormText>Max 150 characters</FormText>
436+
<FormText
437+
style={{
438+
display: 'flex',
439+
justifyContent: 'space-between',
440+
gap: '1rem',
441+
}}
442+
>
443+
<span>Max {DESC_CHAR_LIMIT} characters</span>
444+
<span aria-live="polite">{DESC_CHAR_LIMIT - desc.length} characters left</span>
445+
</FormText>
435446
</FormGroup>
436447
<FormGroup>
437448
<Label for="input-brand">Preferred Make &amp; Model (optional)</Label>

0 commit comments

Comments
 (0)