Skip to content

Commit

Permalink
fix/issue-395/link (#401)
Browse files Browse the repository at this point in the history
* Update main.js

* Update link.js
  • Loading branch information
laurenhitchon authored Jun 12, 2024
1 parent 5428ec8 commit 46ee9c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions src/components/link/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ import { uniqueId } from '../../global/scripts/helpers/utilities'

class ExternalLink {
constructor(element) {
this.link = element
this.element = element
this.uID = uniqueId('external')
this.linkIcon = this.link.querySelector('.nsw-material-icons')
this.linkIconTitle = this.linkIcon.getAttribute('title')
this.linkIcon = this.element.querySelector('.nsw-material-icons')
this.linkIconTitle = this.linkIcon ? this.linkIcon.getAttribute('title') : false
this.linkElement = false
}

init() {
this.link.classList.add('nsw-link', 'nsw-link--icon')
this.constructor.setAttributes(this.link, {
if (this.element.tagName !== 'A') return
this.element.classList.add('nsw-link', 'nsw-link--icon')
this.constructor.setAttributes(this.element, {
target: '_blank',
rel: 'noopener',
})
this.constructor.setAttributes(this.linkIcon, {
focusable: 'false',
'aria-hidden': 'true',
})
this.createElement(this.linkIconTitle)
if (this.linkIcon) {
this.constructor.setAttributes(this.linkIcon, {
focusable: 'false',
'aria-hidden': 'true',
})
}
if (this.linkIconTitle) this.createElement(this.linkIconTitle)
}

createElement(title) {
Expand All @@ -28,8 +31,8 @@ class ExternalLink {
this.linkElement.id = this.uID
this.linkElement.classList.add('sr-only')
this.linkElement.innerText = title
this.link.insertAdjacentElement('afterend', this.linkElement)
this.constructor.setAttributes(this.link, {
this.element.insertAdjacentElement('afterend', this.linkElement)
this.constructor.setAttributes(this.element, {
'aria-describedby': this.uID,
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function initSite() {
const fileUpload = document.querySelectorAll('.js-file-upload')
const filters = document.querySelectorAll('.js-filters')
const globalAlert = document.querySelectorAll('.js-global-alert')
const link = document.querySelectorAll('.js-link')
const link = document.querySelectorAll('a.js-link')
const multiSelect = document.querySelectorAll('.js-multi-select')
const navigation = document.getElementById('main-nav')
const openSearchButton = document.querySelectorAll('.js-open-search')
Expand Down

0 comments on commit 46ee9c3

Please sign in to comment.