Skip to content

Commit

Permalink
fix(ui-dom-utils): fix findFocusable throwing nullpointer exceptions
Browse files Browse the repository at this point in the history
the positioned function was throwing sometimes a nullpointer exception in Canvas tests
TEST PLAN:
just check the code
  • Loading branch information
matyasf committed Aug 24, 2023
1 parent 4c6e998 commit 2169bff
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/ui-dom-utils/src/elementMatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

import { findDOMNode } from './findDOMNode'
import { UIElement } from '@instructure/shared-types'
import type { UIElement } from '@instructure/shared-types'

/**
* ---
Expand Down
4 changes: 2 additions & 2 deletions packages/ui-dom-utils/src/findDOMNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/

import ReactDOM from 'react-dom'
import { ReactInstance, RefObject } from 'react'
import { UIElement } from '@instructure/shared-types'
import type { ReactInstance, RefObject } from 'react'
import type { UIElement } from '@instructure/shared-types'
type ReactNodeWithRef = ReactInstance & {
ref: RefObject<Element | ReactInstance> | Element | ReactInstance
}
Expand Down
12 changes: 6 additions & 6 deletions packages/ui-dom-utils/src/findFocusable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
**/

import { getComputedStyle, findDOMNode, elementMatches } from './'
import { UIElement } from '@instructure/shared-types'
import type { UIElement } from '@instructure/shared-types'

const focusableSelector = [
'a[href]',
Expand Down Expand Up @@ -88,16 +88,16 @@ function hidden(element: Element | Node) {

function positioned(element: Element | Node) {
const POS = ['fixed', 'absolute']
if (POS.includes((element as HTMLElement).style.position.toLowerCase()))
if (POS.includes((element as HTMLElement).style.position?.toLowerCase())) {
return true
}
if (
POS.includes(
(getComputedStyle(element) as CSSStyleDeclaration)
.getPropertyValue('position')
.toLowerCase()
getComputedStyle(element).getPropertyValue('position')?.toLowerCase()
)
)
) {
return true
}
return false
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-dom-utils/src/getComputedStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import { findDOMNode } from './findDOMNode'
import { ownerWindow } from './ownerWindow'
import { canUseDOM } from './canUseDOM'
import { UIElement } from '@instructure/shared-types'
import type { UIElement } from '@instructure/shared-types'

/**
* ---
Expand Down

0 comments on commit 2169bff

Please sign in to comment.