@@ -3009,27 +3009,28 @@ function initSearch(rawSearchIndex) {
30093009 async function addTab ( array , query , display ) {
30103010 const extraClass = display ? " active" : "" ;
30113011
3012- const output = document . createElement ( "div" ) ;
3012+ let output ;
30133013 if ( array . length > 0 ) {
3014+ output = document . createElement ( "ul" ) ;
30143015 output . className = "search-results " + extraClass ;
30153016
3016- const links = Promise . all ( array . map ( async item => {
3017+ const lis = Promise . all ( array . map ( async item => {
30173018 const name = item . name ;
30183019 const type = itemTypes [ item . ty ] ;
30193020 const longType = longItemTypes [ item . ty ] ;
30203021 const typeName = longType . length !== 0 ? `${ longType } ` : "?" ;
30213022
3022- const link = document . createElement ( "a" ) ;
3023- link . className = "result-" + type ;
3024- link . href = item . href ;
3023+ const li = document . createElement ( "li" ) ;
3024+ li . className = "result-" + type ;
30253025
3026- const resultName = document . createElement ( "div " ) ;
3026+ const resultName = document . createElement ( "a " ) ;
30273027 resultName . className = "result-name" ;
3028+ resultName . href = item . href ;
30283029
30293030 resultName . insertAdjacentHTML (
30303031 "beforeend" ,
30313032 `<span class="typename">${ typeName } </span>` ) ;
3032- link . appendChild ( resultName ) ;
3033+ li . appendChild ( resultName ) ;
30333034
30343035 let alias = " " ;
30353036 if ( item . is_alias ) {
@@ -3050,8 +3051,8 @@ ${item.displayPath}<span class="${type}">${name}</span>\
30503051 const displayType = document . createElement ( "div" ) ;
30513052 if ( mappedNames . size > 0 || whereClause . size > 0 ) {
30523053 const tooltip = document . createElement ( "a" ) ;
3053- tooltip . tabIndex = - 1 ;
30543054 tooltip . id = `tooltip-${ item . id } ` ;
3055+ tooltip . href = `#${ tooltip . id } ` ;
30553056 const tooltipCode = document . createElement ( "code" ) ;
30563057 for ( const [ name , qname ] of mappedNames ) {
30573058 const line = document . createElement ( "div" ) ;
@@ -3106,15 +3107,22 @@ ${item.displayPath}<span class="${type}">${name}</span>\
31063107 }
31073108 description . insertAdjacentHTML ( "beforeend" , item . desc ) ;
31083109
3109- link . appendChild ( description ) ;
3110- return link ;
3110+ li . appendChild ( description ) ;
3111+ li . tabIndex = - 1 ;
3112+ li . onclick = ( ) => {
3113+ // allow clicking anywhere on the list item to go to the page
3114+ // even though the link itself is only the name
3115+ resultName . click ( ) ;
3116+ } ;
3117+ return li ;
31113118 } ) ) ;
3112- links . then ( links => {
3113- for ( const link of links ) {
3114- output . appendChild ( link ) ;
3119+ lis . then ( lis => {
3120+ for ( const li of lis ) {
3121+ output . appendChild ( li ) ;
31153122 }
31163123 } ) ;
31173124 } else if ( query . error === null ) {
3125+ output = document . createElement ( "div" ) ;
31183126 output . className = "search-failed" + extraClass ;
31193127 output . innerHTML = "No results :(<br/>" +
31203128 "Try on <a href=\"https://duckduckgo.com/?q=" +
@@ -4176,17 +4184,17 @@ ${item.displayPath}<span class="${type}">${name}</span>\
41764184 // up and down arrow select next/previous search result, or the
41774185 // search box if we're already at the top.
41784186 if ( e . which === 38 ) { // up
4179- const previous = document . activeElement . previousElementSibling ;
4187+ const previous = document . activeElement . parentNode . previousElementSibling ;
41804188 if ( previous ) {
4181- previous . focus ( ) ;
4189+ previous . querySelectorAll ( "a" ) . item ( 0 ) . focus ( ) ;
41824190 } else {
41834191 searchState . focus ( ) ;
41844192 }
41854193 e . preventDefault ( ) ;
41864194 } else if ( e . which === 40 ) { // down
4187- const next = document . activeElement . nextElementSibling ;
4195+ const next = document . activeElement . parentNode . nextElementSibling ;
41884196 if ( next ) {
4189- next . focus ( ) ;
4197+ next . querySelectorAll ( "a" ) . item ( 0 ) . focus ( ) ;
41904198 }
41914199 const rect = document . activeElement . getBoundingClientRect ( ) ;
41924200 if ( window . innerHeight - rect . bottom < rect . height ) {
0 commit comments