File tree Expand file tree Collapse file tree 2 files changed +35
-4
lines changed
Expand file tree Collapse file tree 2 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -19,12 +19,19 @@ export const Container = styled(animated.div)`
1919 font-weight: 600;
2020` ;
2121
22- export const Item = styled . div `
22+ export const Item = styled . button `
2323 transition: 0.2s ease all;
2424 display: flex;
2525 align-items: center;
2626 padding: 0.6rem 1rem;
2727
28+ border: none;
29+ outline: none;
30+ background-color: transparent;
31+ color: inherit;
32+ font-family: inherit;
33+ font-weight: inherit;
34+
2835 border-left: 2px solid transparent;
2936 cursor: pointer;
3037
@@ -45,6 +52,13 @@ export const Item = styled.div`
4552 border-left-color: ${ props =>
4653 props . color ? props . color : theme . secondary ( ) } ;
4754 }
55+
56+ &:focus {
57+ color: ${ props => ( props . color ? props . color : theme . secondary ( ) ) } ;
58+ background-color: ${ ( ) => theme . background2 . lighten ( 0.3 ) ( ) } ;
59+ border-left-color: ${ props =>
60+ props . color ? props . color : theme . secondary ( ) } ;
61+ }
4862` ;
4963
5064export const ItemContainer = styled . div `
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import * as React from 'react';
22import { Spring } from 'react-spring/renderprops' ;
33import Portal from '@codesandbox/common/lib/components/Portal' ;
44
5+ import { ENTER } from '@codesandbox/common/lib/utils/keycodes' ;
6+
57import { Container , Item , ItemContainer } from './elements' ;
68
79class ContextMenu extends React . PureComponent {
@@ -120,18 +122,28 @@ class ContextMenu extends React.PureComponent {
120122 return < ItemContainer key = { i } > { item . map ( mapFunction ) } </ ItemContainer > ;
121123 }
122124
125+ const handlePress = e => {
126+ if ( item . action ( ) ) {
127+ e . preventDefault ( ) ;
128+ this . close ( ) ;
129+ }
130+ } ;
131+
123132 return (
124133 < Item
134+ tabIndex = { 0 }
125135 key = { item . title }
126136 color = { item . color }
127137 onMouseDown = { e => {
128138 e . preventDefault ( ) ;
129139 e . stopPropagation ( ) ;
130140 } }
131141 onMouseUp = { e => {
132- if ( item . action ( ) ) {
133- e . preventDefault ( ) ;
134- this . close ( ) ;
142+ handlePress ( e ) ;
143+ } }
144+ onKeyUp = { e => {
145+ if ( e . keyCode === ENTER ) {
146+ handlePress ( e ) ;
135147 }
136148 } }
137149 >
@@ -151,8 +163,13 @@ class ContextMenu extends React.PureComponent {
151163 < Portal >
152164 < div
153165 ref = { el => {
166+ if ( el && this . el !== el ) {
167+ // First time mounting
168+ el . focus ( ) ;
169+ }
154170 this . el = el ;
155171 } }
172+ tabIndex = "-1"
156173 >
157174 < Spring
158175 from = { { opacity : 0.6 , height : 0 , width : 'auto' } }
You can’t perform that action at this time.
0 commit comments