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

Chore: visually hide labels in the create project form #7015

Merged
merged 2 commits into from
May 13, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions frontend/src/component/common/GeneralSelect/GeneralSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SELECT_ITEM_ID } from 'utils/testIds';
import KeyboardArrowDownOutlined from '@mui/icons-material/KeyboardArrowDownOutlined';
import type { SxProps } from '@mui/system';
import type { Theme } from '@mui/material/styles';
import { visuallyHidden } from '@mui/utils';

export interface ISelectOption {
key: string;
Expand All @@ -30,6 +31,7 @@ export interface IGeneralSelectProps extends Omit<SelectProps, 'onChange'> {
fullWidth?: boolean;
classes?: any;
defaultValue?: string;
visuallyHideLabel?: boolean;
}

const GeneralSelect: React.FC<IGeneralSelectProps> = ({
Expand All @@ -43,6 +45,7 @@ const GeneralSelect: React.FC<IGeneralSelectProps> = ({
className,
classes,
fullWidth,
visuallyHideLabel,
...rest
}) => {
const onSelectChange = (event: SelectChangeEvent) => {
Expand All @@ -57,13 +60,18 @@ const GeneralSelect: React.FC<IGeneralSelectProps> = ({
classes={classes}
fullWidth={fullWidth}
>
<InputLabel htmlFor={id}>{label}</InputLabel>
<InputLabel
sx={visuallyHideLabel ? visuallyHidden : null}
htmlFor={id}
>
{label}
</InputLabel>
<Select
name={name}
disabled={disabled}
onChange={onSelectChange}
className={className}
label={label}
label={visuallyHideLabel ? '' : label}
id={id}
value={value}
IconComponent={KeyboardArrowDownOutlined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const ChangeRequestTable = (props: TableProps) => {
<StyledBox data-loading>
<GeneralSelect
label={`Set required approvals for ${original.environment}`}
visuallyHideLabel

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Getting worse: Large Method
ChangeRequestTable increases from 152 to 153 lines of code, threshold = 120

Suppress

id={`cr-approvals-${original.environment}`}
sx={{ width: '140px' }}
options={approvalOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,21 @@ export const StyledPopover = styled(Popover)(({ theme }) => ({
},
}));

export const StyledTextField = styled(TextField)(({ theme }) => ({
const visuallyHiddenStyles = {
border: 0,
clip: 'rect(0 0 0 0)',
height: 'auto',
margin: 0,
overflow: 'hidden',
padding: 0,
position: 'absolute',
width: '1px',
whiteSpace: 'nowrap',
};

export const StyledDropdownSearch = styled(TextField, {
shouldForwardProp: (prop) => prop !== 'hideLabel',
})<{ hideLabel?: boolean }>(({ theme, hideLabel }) => ({
'& .MuiInputBase-root': {
padding: theme.spacing(0, 1.5),
borderRadius: `${theme.shape.borderRadiusMedium}px`,
Expand All @@ -36,8 +50,16 @@ export const StyledTextField = styled(TextField)(({ theme }) => ({
padding: theme.spacing(0.75, 0),
fontSize: theme.typography.body2.fontSize,
},

...(hideLabel
? {
label: visuallyHiddenStyles,

'fieldset > legend > span': visuallyHiddenStyles,
}
: {}),
}));

export const TableSearchInput = styled(StyledTextField)(({ theme }) => ({
export const TableSearchInput = styled(StyledDropdownSearch)(({ theme }) => ({
maxWidth: '30ch',
}));
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
StyledDropdown,
StyledListItem,
StyledPopover,
StyledTextField,
StyledDropdownSearch,
TableSearchInput,
} from './SelectionButton.styles';
import { ChangeRequestTable } from './ChangeRequestTable';
Expand Down Expand Up @@ -152,12 +152,13 @@ const CombinedSelect: FC<CombinedSelectProps> = ({
}}
>
<StyledDropdown>
<StyledTextField
<StyledDropdownSearch
variant='outlined'
size='small'
value={searchText}
onChange={(event) => setSearchText(event.target.value)}
label={search.label}
hideLabel
placeholder={search.placeholder}
autoFocus
InputProps={{
Expand Down Expand Up @@ -399,6 +400,7 @@ export const TableSelect: FC<TableSelectProps> = ({
size='small'
value={searchText}
onChange={(event) => setSearchText(event.target.value)}
hideLabel
label={search.label}
placeholder={search.placeholder}
autoFocus
Expand Down