Skip to content

Commit

Permalink
Expose CANVAS class in constants (#1184)
Browse files Browse the repository at this point in the history
* Move canvas class name to constants

---------

Co-authored-by: Stepan Kuzmin <[email protected]>
  • Loading branch information
neodescis and stepankuzmin authored Jun 28, 2024
1 parent fa54ad1 commit 5d9a7b8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const classes = {
CANVAS: 'mapboxgl-canvas',
CONTROL_BASE: 'mapboxgl-ctrl',
CONTROL_PREFIX: 'mapboxgl-ctrl-',
CONTROL_BUTTON: 'mapbox-gl-draw_ctrl-draw-btn',
Expand Down
2 changes: 1 addition & 1 deletion src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default function(ctx) {
const isKeyModeValid = code => !(code === 8 || code === 46 || (code >= 48 && code <= 57));

events.keydown = function(event) {
const isMapElement = (event.srcElement || event.target).classList.contains('mapboxgl-canvas');
const isMapElement = (event.srcElement || event.target).classList.contains(Constants.classes.CANVAS);
if (!isMapElement) return; // we only handle events on the map

if ((event.keyCode === 8 || event.keyCode === 46) && ctx.options.controls.trash) {
Expand Down
3 changes: 2 additions & 1 deletion test/utils/key_events.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import createSyntheticEvent from 'synthetic-dom-events';
import * as Constants from '../../src/constants.js';

const classList = ['mapboxgl-canvas'];
const classList = [Constants.classes.CANVAS];
classList.contains = function(cls) {
return classList.indexOf(cls) >= 0;
};
Expand Down

0 comments on commit 5d9a7b8

Please sign in to comment.