@@ -10,7 +10,6 @@ import { ClueSvg, IRefObject } from "./Clue_svg";
1010interface EventTriggers {
1111 onMouseUp : ( event : Event , buttonKey : string ) => void ;
1212 onMouseDown : ( event : Event , buttonKey : string ) => void ;
13- onMouseLeave : ( event : Event , buttonKey : string ) => void ;
1413 onKeyEvent : ( event : KeyboardEvent , active : boolean , key : string ) => void ;
1514}
1615interface IProps {
@@ -42,16 +41,15 @@ export class ClueImage extends React.Component<IProps, {}> {
4241 }
4342 }
4443 componentDidUpdate ( ) {
45- if ( this . svgRef . current ) {
46- if ( this . context === VIEW_STATE . PAUSE ) {
47- disableAllButtons ( this . svgRef . current . getButtons ( ) ) ;
48- } else if ( this . context === VIEW_STATE . RUNNING ) {
49- setupAllButtons (
50- this . props . eventTriggers ,
51- this . svgRef . current . getButtons ( )
52- ) ;
53- }
44+ if ( this . context === VIEW_STATE . PAUSE && this . svgRef . current ) {
45+ disableAllButtons ( this . svgRef . current . getButtons ( ) ) ;
46+ } else if ( this . context === VIEW_STATE . RUNNING && this . svgRef . current ) {
47+ setupAllButtons (
48+ this . props . eventTriggers ,
49+ this . svgRef . current . getButtons ( )
50+ ) ;
5451 }
52+
5553 }
5654 componentWillUnmount ( ) {
5755 window . document . removeEventListener ( "keydown" , this . handleKeyDown ) ;
@@ -89,25 +87,25 @@ export class ClueImage extends React.Component<IProps, {}> {
8987 ) ;
9088 }
9189 public updateButtonAttributes ( key : BUTTONS_KEYS , isActive : boolean ) {
92- if ( this . svgRef . current ) {
93- const button = this . svgRef . current . getButtons ( ) [ key ] . current ;
94- if ( button ) {
95- button . focus ( ) ;
96- if ( isActive ) {
97- button . children [ 0 ] . setAttribute (
98- "class" ,
99- BUTTON_STYLING_CLASSES . KEYPRESSED
100- ) ;
101- } else {
102- button . children [ 0 ] . setAttribute (
103- "class" ,
104- BUTTON_STYLING_CLASSES . DEFAULT
105- ) ;
106- }
107- button . setAttribute ( "pressed" , `${ isActive } ` ) ;
108- button . setAttribute ( "aria-pressed" , `${ isActive } ` ) ;
90+
91+ const button = this . svgRef . current ?. getButtons ( ) [ key ] . current ;
92+ if ( button ) {
93+ button . focus ( ) ;
94+ if ( isActive ) {
95+ button . children [ 0 ] . setAttribute (
96+ "class" ,
97+ BUTTON_STYLING_CLASSES . KEYPRESSED
98+ ) ;
99+ } else {
100+ button . children [ 0 ] . setAttribute (
101+ "class" ,
102+ BUTTON_STYLING_CLASSES . DEFAULT
103+ ) ;
109104 }
105+ button . setAttribute ( "pressed" , `${ isActive } ` ) ;
106+ button . setAttribute ( "aria-pressed" , `${ isActive } ` ) ;
110107 }
108+
111109 }
112110}
113111
@@ -125,9 +123,7 @@ const setupButton = (
125123 buttonElement . onmouseup = e => {
126124 eventTriggers . onMouseUp ( e , key ) ;
127125 } ;
128- buttonElement . onmouseleave = e => {
129- eventTriggers . onMouseLeave ( e , key ) ;
130- } ;
126+
131127 buttonElement . onkeydown = e => {
132128 // ensure that the keydown is enter,
133129 // or else it may register shortcuts twice
@@ -155,7 +151,6 @@ const disableAllButtons = (buttonRefs: IRefObject) => {
155151 // to implement
156152 ref . current . onmousedown = null ;
157153 ref . current . onmouseup = null ;
158- ref . current . onmouseleave = null ;
159154 ref . current . onkeydown = null ;
160155 ref . current . onkeyup = null ;
161156 ref . current . setAttribute ( "class" , BUTTON_CLASSNAME . DEACTIVATED ) ;
0 commit comments