-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(focusable-no-name): work with serial virtual nodes (#2399)
* fix(focusable-no-name): work with serial virtual nodes * allow to incomplete
- Loading branch information
Showing
9 changed files
with
210 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,30 @@ | ||
import AbstractVirtualNode from '../../core/base/virtual-node/abstract-virtual-node'; | ||
import { getNodeFromTree } from '../../core/utils'; | ||
import isHiddenWithCSS from './is-hidden-with-css'; | ||
|
||
/** | ||
* Determines if focusing has been disabled on an element. | ||
* @param {HTMLElement} el The HTMLElement | ||
* @param {HTMLElement|VirtualNode} el The HTMLElement | ||
* @return {Boolean} Whether focusing has been disabled on an element. | ||
*/ | ||
function focusDisabled(el) { | ||
return ( | ||
el.disabled || (el.nodeName.toUpperCase() !== 'AREA' && isHiddenWithCSS(el)) | ||
); | ||
const vNode = el instanceof AbstractVirtualNode ? el : getNodeFromTree(el); | ||
|
||
if (vNode.hasAttr('disabled')) { | ||
return true; | ||
} | ||
|
||
if (vNode.props.nodeName !== 'area') { | ||
// if the virtual node does not have an actual node, treat it | ||
// as not hidden | ||
if (!vNode.actualNode) { | ||
return false; | ||
} | ||
|
||
return isHiddenWithCSS(vNode.actualNode); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
export default focusDisabled; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,33 @@ | ||
import matches from '../matches/matches'; | ||
import getRole from '../aria/get-role'; | ||
import AbstractVirtualNode from '../../core/base/virtual-node/abstract-virtual-node'; | ||
import { getNodeFromTree } from '../../core/utils'; | ||
|
||
const alwaysTitleElements = ['iframe']; | ||
|
||
/** | ||
* Get title text | ||
* @param {HTMLElement}node the node to verify | ||
* @param {HTMLElement|VirtualNode}node the node to verify | ||
* @return {String} | ||
*/ | ||
function titleText(node) { | ||
node = node.actualNode || node; | ||
if (node.nodeType !== 1 || !node.hasAttribute('title')) { | ||
const vNode = | ||
node instanceof AbstractVirtualNode ? node : getNodeFromTree(node); | ||
|
||
if (vNode.props.nodeType !== 1 || !node.hasAttr('title')) { | ||
return ''; | ||
} | ||
|
||
// Some elements return the title even with role=presentation | ||
// This does appear in any spec, but its remarkably consistent | ||
if ( | ||
!matches(node, alwaysTitleElements) && | ||
['none', 'presentation'].includes(getRole(node)) | ||
!matches(vNode, alwaysTitleElements) && | ||
['none', 'presentation'].includes(getRole(vNode)) | ||
) { | ||
return ''; | ||
} | ||
|
||
return node.getAttribute('title'); | ||
return vNode.attr('title'); | ||
} | ||
|
||
export default titleText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.