fix: make properties focusable

This commit is contained in:
Anya Stasiuk 2020-06-02 16:33:24 +03:00 committed by Roman Hotsiy
parent 442014c06d
commit 05fd7543a2
3 changed files with 30 additions and 6 deletions

View File

@ -62,7 +62,7 @@ export const PropertyNameCell = styled(PropertyCell)`
vertical-align: top;
line-height: 20px;
white-space: nowrap;
font-size: 0.929em;
font-size: 13px;
font-family: ${props => props.theme.typography.code.fontFamily};
&.deprecated {

View File

@ -5,8 +5,19 @@ import { PropertyNameCell } from './fields-layout';
import { ShelfIcon } from './shelfs';
export const ClickablePropertyNameCell = styled(PropertyNameCell)`
cursor: pointer;
button {
background-color: transparent;
border: 0;
outline: 0;
font-size: 13px;
font-family: ${props => props.theme.typography.code.fontFamily};
cursor: pointer;
padding: 0;
color: ${props => props.theme.colors.text.primary};
&:focus {
font-weight: ${({ theme }) => theme.typography.fontWeightBold};
}
}
${ShelfIcon} {
height: ${({ theme }) => theme.schema.arrow.size};
width: ${({ theme }) => theme.schema.arrow.size};

View File

@ -37,6 +37,14 @@ export class Field extends React.Component<FieldProps> {
this.props.field.toggle();
}
};
handleKeyPress = e => {
if (e.key === 'Enter') {
e.preventDefault();
this.toggle();
}
};
render() {
const { className, field, isLast, expandByDefault } = this.props;
const { name, deprecated, required, kind } = field;
@ -46,14 +54,19 @@ export class Field extends React.Component<FieldProps> {
const paramName = withSubSchema ? (
<ClickablePropertyNameCell
onClick={this.toggle}
className={deprecated ? 'deprecated' : ''}
kind={kind}
title={name}
>
<PropertyBullet />
{name}
<ShelfIcon direction={expanded ? 'down' : 'right'} />
<button
onClick={this.toggle}
onKeyPress={this.handleKeyPress}
aria-label="expand properties"
>
{name}
<ShelfIcon direction={expanded ? 'down' : 'right'} />
</button>
{required && <RequiredLabel> required </RequiredLabel>}
</ClickablePropertyNameCell>
) : (