Skip to content

Commit

Permalink
fix(modal-#1570):ARIA properties added to modal whilst being unopened (
Browse files Browse the repository at this point in the history
…#1680)

* fix(modal-#1570):ARIA properties added to modal whilst being unopened

* fix(modal):removal of extra class 'cds--modal'
  • Loading branch information
RiyaJethwa authored Nov 1, 2023
1 parent 43009e6 commit ff62ad6
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions packages/core/src/components/essentials/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,37 @@ export class Modal extends Component {
}

handleShowModal = () => {
this.modal
.attr('data-modal', true)
.attr('class', 'cds--modal')
.attr('role', 'dialog')
.attr('aria-modal', true)
.attr('aria-labelledby', 'modal-title')
.attr('aria-describedby', 'modal-description')
.attr('tabindex', -1)

this.modal.html(this.getModalHTML())
this.modal
.select('div.cds--modal-footer button.cds--btn')
.on('click', () => this.model.exportToCSV())

const modalInstance = CarbonModalComponent.create(this.modal.node())
modalInstance.show()

//catches when modal gets closed
document.addEventListener('modal-hidden', this.handleHideModal)
}

handleHideModal = () => {
this.modal
.attr('role', null)
.attr('aria-modal', null)
.attr('aria-labelledby', null)
.attr('aria-describedby', null)
.attr('tabindex', null)

//removes event listener when modal is closed
document.removeEventListener('modal-hidden', this.handleHideModal)
}

addEventListeners() {
Expand Down Expand Up @@ -99,27 +123,24 @@ export class Modal extends Component {
</div>`
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
render(animate = false) {
const options = this.model.getOptions() as ChartOptions
if (!this.isEventListenerAdded) {
// Grab the tooltip element
const holder = select(this.services.domUtils.getHolder()) as Selection<HTMLDivElement, any, Element, any>
const holder = select(this.services.domUtils.getHolder()) as Selection<
HTMLDivElement,
any,
Element,
any
>
const chartprefix = getProperty(options, 'style', 'prefix') as string
this.modal = DOMUtils.appendOrSelect(holder, `div.${carbonPrefix}--${chartprefix}--modal`)

this.addEventListeners()
this.isEventListenerAdded = true
this.modal
.attr('data-modal', true)
.attr('class', 'cds--modal cds--modal')
.attr('role', 'dialog')
.attr('aria-modal', true)
.attr('aria-labelledby', 'modal-title')
.attr('aria-describedby', 'modal-description')
.attr('tabindex', -1)
}
}

Expand Down

0 comments on commit ff62ad6

Please sign in to comment.