diff --git a/lib/core/utils/get-scroll.js b/lib/core/utils/get-scroll.js index edbaf5310e..0771e71f3c 100644 --- a/lib/core/utils/get-scroll.js +++ b/lib/core/utils/get-scroll.js @@ -6,7 +6,7 @@ * @param {buffer} (Optional) allowed negligence in overflow * @returns {Object | undefined} */ -function getScroll(elm, buffer = 0) { + export default function getScroll(elm, buffer = 0) { const overflowX = elm.scrollWidth > elm.clientWidth + buffer; const overflowY = elm.scrollHeight > elm.clientHeight + buffer; @@ -19,12 +19,8 @@ function getScroll(elm, buffer = 0) { } const style = window.getComputedStyle(elm); - const overflowXStyle = style.getPropertyValue('overflow-x'); - const overflowYStyle = style.getPropertyValue('overflow-y'); - const scrollableX = - overflowXStyle !== 'visible' && overflowXStyle !== 'hidden'; - const scrollableY = - overflowYStyle !== 'visible' && overflowYStyle !== 'hidden'; + const scrollableX = isScrollable(style, 'overflow-x'); + const scrollableY = isScrollable(style, 'overflow-y'); /** * check direction of `overflow` and `scrollable` @@ -38,4 +34,7 @@ function getScroll(elm, buffer = 0) { } } -export default getScroll; +function isScrollable(style, prop) { + const overflowProp = style.getPropertyValue(prop); + return ['scroll', 'auto'].includes(overflowProp); +} diff --git a/test/core/utils/get-scroll.js b/test/core/utils/get-scroll.js index c3343ea8f8..33ceffeb13 100644 --- a/test/core/utils/get-scroll.js +++ b/test/core/utils/get-scroll.js @@ -45,6 +45,18 @@ describe('axe.utils.getScroll', function() { assert.isUndefined(actual); }); + it('returns undefined when element overflow is clip', function() { + var target = queryFixture( + '
' + + '
' + + '

Content

' + + '
' + + '
' + ); + var actual = axe.utils.getScroll(target.actualNode); + assert.isUndefined(actual); + }); + it('returns scroll offset when element overflow is auto', function() { var target = queryFixture( '
' + diff --git a/test/integration/rules/scrollable-region-focusable/scrollable-region-focusable.html b/test/integration/rules/scrollable-region-focusable/scrollable-region-focusable.html index 7ee3285851..c920d8e570 100644 --- a/test/integration/rules/scrollable-region-focusable/scrollable-region-focusable.html +++ b/test/integration/rules/scrollable-region-focusable/scrollable-region-focusable.html @@ -126,3 +126,9 @@
+ +
+
+

Content

+
+
\ No newline at end of file