Skip to content

Commit e1c98ac

Browse files
committed
Stop 'enter' on lots of IconButtons from firing twice & breaking things
Because these are already buttons, affordances like enter=click are automatic. In most cases it doesn't matter, but for expand/collapse toggles it does, because it stopped the button working: it toggled instantly back to the original state due to the double press.
1 parent 6acfe42 commit e1c98ac

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

src/components/common/copy-button.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export const CopyButtonPill = (p: { content: string, children?: React.ReactNode
6767

6868
return <PillButton
6969
tabIndex={0}
70-
onKeyDown={clickOnEnter}
7170
onClick={() => {
7271
copyToClipboard(p.content);
7372
showSuccess();

src/components/common/editable-pairs.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ export class EditablePairs<R> extends React.Component<EditablePairsProps<R>> {
196196
values.splice(i, 1);
197197
onChangeValues(values);
198198
})}
199-
onKeyPress={clickOnEnter}
200199
>
201200
<Icon icon={['far', 'trash-alt']} />
202201
</PairDeleteButton>

src/components/common/icon-button.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as React from 'react';
33
import { styled } from '../../styles'
44
import { Icon, IconProp } from '../../icons';
55

6-
import { clickOnEnter } from '../component-utils';
76
import { UnstyledButton, UnstyledButtonLink } from './inputs';
87

98
export const IconButton = styled((p: {
@@ -20,7 +19,6 @@ export const IconButton = styled((p: {
2019
tabIndex={p.disabled ? -1 : 0}
2120
disabled={p.disabled}
2221
onClick={p.onClick}
23-
onKeyPress={clickOnEnter}
2422
>
2523
<Icon
2624
icon={p.icon}

src/components/mock/mock-item-menu.tsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as _ from 'lodash';
22
import * as React from 'react';
33

44
import { styled, css } from '../../styles';
5-
import { Icon, IconProp } from '../../icons';
5+
import { IconProp } from '../../icons';
66

7-
import { clickOnEnter } from '../component-utils';
7+
import { IconButton } from '../common/icon-button';
88

99
export const IconMenu = styled.div<{ topOffset: number }>`
1010
position: absolute;
@@ -22,13 +22,12 @@ export const IconMenuButton = styled(React.memo((p: {
2222
title: string,
2323
onClick: (event: React.MouseEvent) => void,
2424
disabled?: boolean
25-
}) => <Icon
25+
}) => <IconButton
2626
className={p.className}
2727
icon={p.icon}
2828
title={p.title}
29-
tabIndex={p.disabled ? -1 : 0}
30-
onKeyPress={clickOnEnter}
31-
onClick={p.disabled ? _.noop : p.onClick}
29+
disabled={p.disabled}
30+
onClick={p.onClick}
3231
/>))`
3332
padding: 5px;
3433
margin: 0 5px;
@@ -37,18 +36,22 @@ export const IconMenuButton = styled(React.memo((p: {
3736
3837
font-size: 1.2em;
3938
40-
${p => p.disabled
41-
? css`
42-
color: ${p => p.theme.containerWatermark};
43-
`
44-
: css`
45-
cursor: pointer;
46-
color: ${p => p.theme.primaryInputBackground};
47-
48-
&:hover, &:focus {
49-
outline: none;
50-
color: ${p => p.theme.popColor};
51-
}
52-
`
39+
> svg {
40+
display: block;
41+
}
42+
43+
:disabled {
44+
opacity: 1;
45+
color: ${p => p.theme.containerWatermark};
46+
}
47+
48+
:not(:disabled) {
49+
cursor: pointer;
50+
color: ${p => p.theme.primaryInputBackground};
51+
52+
&:hover, &:focus {
53+
outline: none;
54+
color: ${p => p.theme.popColor};
55+
}
5356
}
5457
`;

src/components/mock/mock-rule-row.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ const RowContainer = styled(LittleCard)<{
6969
width: calc(100% - ${p => p.depth * 40}px);
7070
margin-left: ${p => p.depth * 40}px;
7171
72-
svg {
73-
margin: 0 5px;
74-
}
75-
7672
display: flex;
7773
flex-wrap: wrap;
7874
flex-direction: row;
@@ -137,6 +133,10 @@ export const AddRuleRow = styled((p: {
137133
Add a new rule to rewrite requests or responses
138134
</RowContainer>
139135
)`
136+
> svg {
137+
margin: 0 5px;
138+
}
139+
140140
margin-top: 20px;
141141
142142
justify-content: center;

0 commit comments

Comments
 (0)