@@ -95,7 +95,7 @@ export var MapMLLayer = L.Layer.extend({
9595 var c = document . createElement ( 'div' ) ;
9696 c . classList . add ( "mapml-popup-content" ) ;
9797 c . insertAdjacentHTML ( 'afterbegin' , properties . innerHTML ) ;
98- geometry . bindPopup ( c , { autoPan :false , closeButton : false , minWidth : 108 } ) ;
98+ geometry . bindPopup ( c , { autoPan :false , minWidth : 108 } ) ;
9999 }
100100 }
101101 } ) ;
@@ -125,7 +125,7 @@ export var MapMLLayer = L.Layer.extend({
125125 var c = document . createElement ( 'div' ) ;
126126 c . classList . add ( "mapml-popup-content" ) ;
127127 c . insertAdjacentHTML ( 'afterbegin' , properties . innerHTML ) ;
128- geometry . bindPopup ( c , { autoPan :false , closeButton : false , minWidth : 108 } ) ;
128+ geometry . bindPopup ( c , { autoPan :false , minWidth : 108 } ) ;
129129 }
130130 }
131131 } ) . addTo ( map ) ;
@@ -1162,8 +1162,7 @@ export var MapMLLayer = L.Layer.extend({
11621162 content = popup . _container . getElementsByClassName ( "mapml-popup-content" ) [ 0 ] ;
11631163
11641164 content . setAttribute ( "tabindex" , "-1" ) ;
1165- content . focus ( ) ;
1166- popup . _count = 0 ;
1165+ popup . _count = 0 ; // used for feature pagination
11671166
11681167 if ( popup . _source . _eventParents ) { // check if the popup is for a feature or query
11691168 layer = popup . _source . _eventParents [ Object . keys ( popup . _source . _eventParents ) [ 0 ] ] ; // get first parent of feature, there should only be one
@@ -1232,7 +1231,11 @@ export var MapMLLayer = L.Layer.extend({
12321231 L . DomEvent . on ( controlFocusButton , 'click' , L . DomEvent . stop ) ;
12331232 L . DomEvent . on ( controlFocusButton , 'click' , ( e ) => {
12341233 map . closePopup ( ) ;
1235- map . _controlContainer . focus ( ) ;
1234+ if ( map . _controlContainer . firstElementChild . firstElementChild . firstElementChild ) {
1235+ map . _controlContainer . firstElementChild . firstElementChild . firstElementChild . focus ( ) ;
1236+ } else {
1237+ map . _controlContainer . focus ( ) ;
1238+ }
12361239 } , popup ) ;
12371240
12381241 let divider = L . DomUtil . create ( "hr" ) ;
@@ -1241,31 +1244,60 @@ export var MapMLLayer = L.Layer.extend({
12411244 popup . _navigationBar = div ;
12421245 popup . _content . appendChild ( divider ) ;
12431246 popup . _content . appendChild ( div ) ;
1244-
1247+
1248+ content . focus ( ) ;
12451249
12461250 if ( path ) {
12471251 // e.target = this._map
12481252 // Looks for keydown, more specifically tab and shift tab
12491253 map . on ( "keydown" , focusFeature ) ;
1250- // if popup closes then the focusFeature handler can be removed
1251- map . on ( "popupclose " , removeHandlers ) ;
1254+ } else {
1255+ map . on ( "keydown " , focusMap ) ;
12521256 }
12531257 // When popup is open, what gets focused with tab needs to be done using JS as the DOM order is not in an accessibility friendly manner
12541258 function focusFeature ( focusEvent ) {
1255- if ( focusEvent . originalEvent . path [ 0 ] . title === "Focus Controls" && + focusEvent . originalEvent . keyCode === 9 ) {
1259+ let isTab = focusEvent . originalEvent . keyCode === 9 ,
1260+ shiftPressed = focusEvent . originalEvent . shiftKey ;
1261+ if ( ( focusEvent . originalEvent . path [ 0 ] . classList . contains ( "leaflet-popup-close-button" ) && isTab && ! shiftPressed ) || focusEvent . originalEvent . keyCode === 27 ) {
12561262 L . DomEvent . stop ( focusEvent ) ;
1257- path . focus ( ) ;
1258- } else if ( focusEvent . originalEvent . shiftKey && + focusEvent . originalEvent . keyCode === 9 ) {
12591263 map . closePopup ( popup ) ;
1260- L . DomEvent . stop ( focusEvent ) ;
12611264 path . focus ( ) ;
1265+ } else if ( ( focusEvent . originalEvent . path [ 0 ] . title === "Focus Map" || focusEvent . originalEvent . path [ 0 ] . classList . contains ( "mapml-popup-content" ) ) && isTab && shiftPressed ) {
1266+ setTimeout ( ( ) => { //timeout needed so focus of the feature is done even after the keypressup event occurs
1267+ L . DomEvent . stop ( focusEvent ) ;
1268+ map . closePopup ( popup ) ;
1269+ path . focus ( ) ;
1270+ } , 0 ) ;
1271+ }
1272+ }
1273+
1274+ function focusMap ( focusEvent ) {
1275+ let isTab = focusEvent . originalEvent . keyCode === 9 ,
1276+ shiftPressed = focusEvent . originalEvent . shiftKey ;
1277+
1278+ if ( ( focusEvent . originalEvent . keyCode === 13 && focusEvent . originalEvent . path [ 0 ] . classList . contains ( "leaflet-popup-close-button" ) ) || focusEvent . originalEvent . keyCode === 27 ) {
1279+ L . DomEvent . stopPropagation ( focusEvent ) ;
1280+ map . _container . focus ( ) ;
1281+ map . closePopup ( popup ) ;
1282+ if ( focusEvent . originalEvent . keyCode !== 27 ) map . _popupClosed = true ;
1283+ } else if ( isTab && focusEvent . originalEvent . path [ 0 ] . classList . contains ( "leaflet-popup-close-button" ) ) {
1284+ map . closePopup ( popup ) ;
1285+ } else if ( ( focusEvent . originalEvent . path [ 0 ] . title === "Focus Map" || focusEvent . originalEvent . path [ 0 ] . classList . contains ( "mapml-popup-content" ) ) && isTab && shiftPressed ) {
1286+ setTimeout ( ( ) => { //timeout needed so focus of the feature is done even after the keypressup event occurs
1287+ L . DomEvent . stop ( focusEvent ) ;
1288+ map . closePopup ( popup ) ;
1289+ map . _container . focus ( ) ;
1290+ } , 0 ) ;
12621291 }
12631292 }
12641293
1294+ // if popup closes then the focusFeature handler can be removed
1295+ map . on ( "popupclose" , removeHandlers ) ;
12651296 function removeHandlers ( removeEvent ) {
12661297 if ( removeEvent . popup === popup ) {
12671298 map . off ( "keydown" , focusFeature ) ;
1268- map . off ( "popupclose" , removeHandlers ) ;
1299+ map . off ( "keydown" , focusMap ) ;
1300+ map . off ( 'popupclose' , removeHandlers ) ;
12691301 }
12701302 }
12711303 } ,
0 commit comments