Skip to content

Commit

Permalink
fix: make properties focusable
Browse files Browse the repository at this point in the history
  • Loading branch information
stasiukanya authored and RomanHotsiy committed Jul 13, 2020
1 parent 442014c commit 05fd754
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/common-elements/fields-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 13 additions & 2 deletions src/common-elements/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
19 changes: 16 additions & 3 deletions src/components/Fields/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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>
) : (
Expand Down

0 comments on commit 05fd754

Please sign in to comment.