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

tooltip for autocomplete textfield #84

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Corrected the focus styling of `preview icon` in the `Tile` component and `zoom buttons` in the `Preview` component to meet the required contrast ratio
- Corrected the focus styling of endActionButtons in `DataGrid` component.
- Added `role="alert"` to the snackbar message text for improved screen reader accessibility.
- Added tooltip to the `Autocomplete` textfield for the truncated values.

### Changed
- Added keyboard accessibility to the header in `DataGrid` component
Expand Down
19 changes: 18 additions & 1 deletion src/Autocomplete/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import React from 'react';
import MuiAutocomplete, { AutocompleteProps as MuiAutocompleteProps } from '@mui/material/Autocomplete';
import { Components, Theme } from '@mui/material';
import Tooltip from '../Tooltip/Tooltip';

Check failure on line 19 in src/Autocomplete/Autocomplete.tsx

View workflow job for this annotation

GitHub Actions / PR check build & lint

`../Tooltip/Tooltip` import should occur after import of `@mui/material/styles`
import CaretDownIcon from '@hcl-software/enchanted-icons/dist/carbon/es/caret--down';
import ClearIcon from '@hcl-software/enchanted-icons/dist/carbon/es/close';
import MuiFormHelperText from '@mui/material/FormHelperText';
Expand Down Expand Up @@ -110,6 +111,17 @@
const helperTextId = props.helperText && props.id ? `${props.id}-helper-text` : undefined;
const muiFormControlProps = getMuiFormControlProps(props);
const inputLabelAndActionProps = getInputLabelAndActionProps(props, isFocus);
const textfieldRef = React.useRef<HTMLInputElement>(null);
const [isValueOverFlowing, setIsValueOverFlowing] = React.useState(false);

React.useEffect(() => {
const textFieldElement = textfieldRef.current;
if (textFieldElement && textFieldElement.scrollWidth > textFieldElement.clientWidth) {
setIsValueOverFlowing(true);
} else {
setIsValueOverFlowing(false);
}
}, [props.value]);

return (
<AutoCompleteContainer className="autocomplete-container">
Expand Down Expand Up @@ -144,7 +156,12 @@
endAdornmentAction,
value: props.value,
};
return <TextField {...textFieldArgs} />;
const tooltipTitle = isValueOverFlowing? textfieldRef.current?.value || '' : '';

Check failure on line 159 in src/Autocomplete/Autocomplete.tsx

View workflow job for this annotation

GitHub Actions / PR check build & lint

Operator '?' must be spaced
return (
<Tooltip title={tooltipTitle}>
<TextField {...textFieldArgs} inputRef={textfieldRef} />
</Tooltip>
);
}}
/>
<MuiFormHelperText id={helperTextId} sx={{ marginTop: nonEdit ? '0px' : '4px' }}>{helperText}</MuiFormHelperText>
Expand Down
Loading