瀏覽代碼

Merge pull request #632 from DouyinFE/fix_slider_special_env

fix: fix slider throw error in shadowDOM or other DocumentFragment env
代强 3 年之前
父節點
當前提交
fa4a8decde
共有 1 個文件被更改,包括 2 次插入2 次删除
  1. 2 2
      packages/semi-foundation/slider/foundation.ts

+ 2 - 2
packages/semi-foundation/slider/foundation.ts

@@ -240,7 +240,7 @@ export default class SliderFoundation extends BaseFoundation<SliderAdapter> {
         const scroll = (node: Element) => regex.test(style(node, 'overflow') + style(node, 'overflow-y') + style(node, 'overflow-x'));
 
         const scrollParent = (node: Element): Element => (
-            !node || node === document.body ? document.body : scroll(node) ? node : scrollParent(node.parentNode as Element)
+            !node || (node === document.body || !(node instanceof Element)) ? document.body : scroll(node) ? node : scrollParent(node.parentNode as Element)
         );
 
         return scrollParent(el);
@@ -320,7 +320,7 @@ export default class SliderFoundation extends BaseFoundation<SliderAdapter> {
         } else {
             compareValue = currentValue;
         }
-        if (step !== 1) { // Find nearest step point 
+        if (step !== 1) { // Find nearest step point
             stepValue = Math.round(stepValue / step) * step;
         }
         if (range && stepValue !== compareValue) {