Skip to content

Commit

Permalink
Show error feedback differently based on isTabled attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
fongsean committed Oct 19, 2023
1 parent 113e828 commit 2501799
Showing 1 changed file with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import React, { useRef } from 'react';
import type { PropsWithIsTabledAttribute } from '../../../../interfaces/renderProps.interface';
import { StandardTextField } from '../../Textfield.styles';
import DatePicker from './DatePicker';
import Tooltip from '@mui/material/Tooltip';

interface CustomDateFieldProps extends PropsWithIsTabledAttribute {
linkId: string;
Expand Down Expand Up @@ -55,37 +56,39 @@ function CustomDateField(props: CustomDateFieldProps) {
const anchorRef: RefObject<HTMLDivElement> = useRef(null);

return (
<StandardTextField
id={linkId}
ref={anchorRef}
fullWidth
isTabled={isTabled}
value={input}
error={!!feedback}
onChange={(e: ChangeEvent<HTMLInputElement>) => onInputChange(e.target.value)}
label={displayPrompt}
placeholder={entryFormat !== '' ? entryFormat : 'DD/MM/YYYY'}
disabled={readOnly}
size="small"
focused={isFocused}
onFocus={() => setFocused(true)}
onBlur={() => setFocused(false)}
InputProps={{
endAdornment: (
<>
<DatePicker
valueString={valueDate}
anchorEl={anchorRef.current}
onSelectDate={(valueDayjs: Dayjs) => {
onSelectDate(valueDayjs.format('DD/MM/YYYY'));
}}
onFocus={(focus) => setFocused(focus)}
/>
</>
)
}}
helperText={feedback}
/>
<Tooltip title={isTabled ? feedback : ''}>
<StandardTextField
id={linkId}
ref={anchorRef}
fullWidth
isTabled={isTabled}
value={input}
error={!!feedback}
onChange={(e: ChangeEvent<HTMLInputElement>) => onInputChange(e.target.value)}
label={displayPrompt}
placeholder={entryFormat !== '' ? entryFormat : 'DD/MM/YYYY'}
disabled={readOnly}
size="small"
focused={isFocused}
onFocus={() => setFocused(true)}
onBlur={() => setFocused(false)}
InputProps={{
endAdornment: (
<>
<DatePicker
valueString={valueDate}
anchorEl={anchorRef.current}
onSelectDate={(valueDayjs: Dayjs) => {
onSelectDate(valueDayjs.format('DD/MM/YYYY'));
}}
onFocus={(focus) => setFocused(focus)}
/>
</>
)
}}
helperText={isTabled ? '' : feedback}
/>
</Tooltip>
);
}

Expand Down

0 comments on commit 2501799

Please sign in to comment.