@@ -164,11 +164,17 @@ export function addFeatureToMap(feature, drawPlugin, map) {
164164 * Returns HTML summary list for the features
165165 * @param {FeatureCollection } features - the features
166166 * @param {string } mapId - the ID of the map
167+ * @param {boolean } [disabled] - render the list with disabled links
167168 * @param {boolean } [readonly] - render the list in readonly mode
168169 */
169- export function createFeaturesHTML ( features , mapId , readonly = false ) {
170+ export function createFeaturesHTML (
171+ features ,
172+ mapId ,
173+ disabled = false ,
174+ readonly = false
175+ ) {
170176 return `<dl class="govuk-summary-list">
171- ${ features . map ( ( feature , index ) => createFeatureHTML ( feature , index , mapId , readonly ) ) . join ( '\n' ) }
177+ ${ features . map ( ( feature , index ) => createFeatureHTML ( feature , index , mapId , disabled , readonly ) ) . join ( '\n' ) }
172178 </dl>`
173179}
174180
@@ -186,9 +192,16 @@ export function focusFeature(feature, mapProvider) {
186192 * @param {Feature } feature - the geo feature
187193 * @param {number } index - the feature index
188194 * @param {string } mapId - the ID of the map
189- * @param {boolean } readonly - render the list item in readonly mode
195+ * @param {boolean } [disabled] - render the list with disabled links
196+ * @param {boolean } [readonly] - render the list item in readonly mode
190197 */
191- function createFeatureHTML ( feature , index , mapId , readonly ) {
198+ export function createFeatureHTML (
199+ feature ,
200+ index ,
201+ mapId ,
202+ disabled = false ,
203+ readonly = false
204+ ) {
192205 const flattened = feature . geometry . coordinates . flat ( 2 )
193206
194207 const points = [ ]
@@ -203,13 +216,13 @@ function createFeatureHTML(feature, index, mapId, readonly) {
203216
204217 // Change action link
205218 const changeAction = ( ) => `<li class="govuk-summary-list__actions-list-item">
206- <a class="govuk-link govuk-link--no-visited-state" href="#${ mapId } " data-action="edit" data-id="${ feature . id } "
219+ <a class="govuk-link govuk-link--no-visited-state ${ disabled ? 'govuk-link--disabled' : '' } " href="#${ mapId } " data-action="edit" data-id="${ feature . id } "
207220 data-type="${ feature . geometry . type } ">Update<span class="govuk-visually-hidden"> location</span></a>
208221</li>`
209222
210223 // Delete action link
211224 const deleteAction = ( ) => `<li class="govuk-summary-list__actions-list-item">
212- <a class="govuk-link govuk-link--no-visited-state" href="#" data-action="delete" data-id="${ feature . id } "
225+ <a class="govuk-link govuk-link--no-visited-state ${ disabled ? 'govuk-link--disabled' : '' } " href="#" data-action="delete" data-id="${ feature . id } "
213226 data-type="${ feature . geometry . type } ">Delete<span class="govuk-visually-hidden"> location</span></a>
214227</li>`
215228
@@ -415,8 +428,8 @@ function getFeaturesManager(geojson) {
415428 * @returns {RenderList }
416429 */
417430function getListRenderer ( geojson , mapId , listEl , renderValue ) {
418- return function renderList ( ) {
419- const html = createFeaturesHTML ( geojson . features , mapId )
431+ return function renderList ( disabled = false ) {
432+ const html = createFeaturesHTML ( geojson . features , mapId , disabled )
420433
421434 listEl . innerHTML = html
422435
@@ -523,7 +536,7 @@ function createContainers(geospatialInput, index) {
523536function onMapReadyFactory ( context ) {
524537 const { map, activeFeatureManager, uiManager, interactPlugin, drawPlugin } =
525538 context
526- const { toggleActionButtons } = uiManager
539+ const { toggleActionButtons, renderList } = uiManager
527540 const { resetActiveFeature } = activeFeatureManager
528541
529542 /**
@@ -542,6 +555,7 @@ function onMapReadyFactory(context) {
542555 onClick : ( ) => {
543556 resetActiveFeature ( )
544557 toggleActionButtons ( true )
558+ renderList ( true )
545559 interactPlugin . enable ( )
546560 } ,
547561 mobile : { slot : 'actions' } ,
@@ -556,6 +570,7 @@ function onMapReadyFactory(context) {
556570 onClick : ( ) => {
557571 resetActiveFeature ( )
558572 toggleActionButtons ( true )
573+ renderList ( true )
559574 drawPlugin . newPolygon ( generateID ( ) , polygonFeatureProperties )
560575 } ,
561576 mobile : { slot : 'actions' } ,
@@ -570,6 +585,7 @@ function onMapReadyFactory(context) {
570585 onClick : ( ) => {
571586 resetActiveFeature ( )
572587 toggleActionButtons ( true )
588+ renderList ( true )
573589 drawPlugin . newLine ( generateID ( ) , lineFeatureProperties )
574590 } ,
575591 mobile : { slot : 'actions' } ,
@@ -589,6 +605,7 @@ function onMapReadyFactory(context) {
589605 const { listEl } = uiManager
590606 listEl . addEventListener ( 'click' , onListElClickFactory ( context ) , false )
591607 listEl . addEventListener ( 'change' , onListElChangeFactory ( context ) , false )
608+ listEl . addEventListener ( 'keydown' , onListElKeydownFactory ( ) , false )
592609 }
593610}
594611
@@ -679,7 +696,7 @@ function onDrawEditedFactory(context) {
679696 */
680697function onDrawCancelledFactory ( context ) {
681698 const { uiManager, activeFeatureManager } = context
682- const { toggleActionButtons } = uiManager
699+ const { toggleActionButtons, renderList } = uiManager
683700 const { resetActiveFeature } = activeFeatureManager
684701
685702 /**
@@ -688,6 +705,7 @@ function onDrawCancelledFactory(context) {
688705 return function onDrawCancelled ( ) {
689706 toggleActionButtons ( false )
690707 resetActiveFeature ( )
708+ renderList ( )
691709 }
692710}
693711
@@ -815,6 +833,7 @@ function onListElClickFactory(context) {
815833 }
816834
817835 toggleActionButtons ( true )
836+ renderList ( true )
818837 }
819838
820839 /**
@@ -859,7 +878,7 @@ function onListElClickFactory(context) {
859878}
860879
861880/**
862- * Callback factory function that fires a 'change' event is fired on the list container
881+ * Callback factory function that fires when a 'change' event is fired on the list container
863882 * @param {Context } context - the UI context
864883 */
865884function onListElChangeFactory ( context ) {
@@ -891,6 +910,29 @@ function onListElChangeFactory(context) {
891910 }
892911}
893912
913+ /**
914+ * Callback factory function that fires when a 'keydown' event is fired on the list container
915+ */
916+ function onListElKeydownFactory ( ) {
917+ /**
918+ * List container delegated 'keydown' events handler
919+ * Fixes the issue of pressing "Enter" key in the description input triggering the map search
920+ * @param {KeyboardEvent } e
921+ */
922+ return function ( e ) {
923+ const target = e . target
924+
925+ if ( ! ( target instanceof HTMLInputElement ) ) {
926+ return
927+ }
928+
929+ if ( e . code === 'Enter' || e . code === 'NumpadEnter' ) {
930+ e . preventDefault ( )
931+ e . stopPropagation ( )
932+ }
933+ }
934+ }
935+
894936/**
895937 * @import { MapsEnvironmentConfig, InteractiveMap } from '~/src/client/javascripts/map.js'
896938 */
@@ -960,6 +1002,7 @@ function onListElChangeFactory(context) {
9601002/**
9611003 * Renders the features into the list
9621004 * @callback RenderList
1005+ * @param {boolean } [disabled] - whether to render the list with disabled links
9631006 * @returns {void }
9641007 */
9651008
0 commit comments