Skip to content

Commit

Permalink
fix(@clayui/list): When running on IE11, use `target.ownerDocument.ac…
Browse files Browse the repository at this point in the history
…tiveElement` instead of `event.relatedTarget` on onBlur callbacks

See: facebook/react#3751
  • Loading branch information
diegonvs committed Jul 20, 2020
1 parent 78f508a commit 0f204d6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/clay-list/src/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import classNames from 'classnames';
import React from 'react';

const isIE11 = typeof window !== 'undefined' && 'msCrypto' in window;

interface IProps extends React.HTMLAttributes<HTMLLIElement> {
/**
* Flag to indicate if the `list-group-item-action` class should be applied.
Expand Down Expand Up @@ -61,7 +63,18 @@ const ClayListItem = React.forwardRef<HTMLLIElement, IProps>(
'list-group-item-disabled': disabled,
'list-group-item-flex': flex,
})}
onBlur={({currentTarget, relatedTarget}) => {
onBlur={({
currentTarget,
relatedTarget: relatedTargetElement,
target,
}) => {
// IE11 doesn't support event.relatedTarget, but you can use
// document.activeElement.
const relatedTarget =
isIE11 && !relatedTargetElement
? target.ownerDocument.activeElement
: relatedTargetElement;

if (
relatedTarget &&
!currentTarget.contains(relatedTarget as Node)
Expand Down

0 comments on commit 0f204d6

Please sign in to comment.