Skip to content

Commit

Permalink
fix: add special treatment for textareas, fixes #74
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Jul 3, 2022
1 parent 3319638 commit af8fd75
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/handleScroll.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { Axis } from './types';

const elementCouldBeVScrolled = (node: HTMLElement): boolean => {
const styles = window.getComputedStyle(node);

return (
styles.overflowY !== 'hidden' && // not-not-scrollable
!(styles.overflowY === styles.overflowX && styles.overflowY === 'visible') // scrollable
);
};
const alwaysContainsScroll = (node: HTMLElement): boolean =>
// textarea will always _contain_ scroll inside self. It only can be hidden
node.tagName === 'TEXTAREA';

const elementCouldBeHScrolled = (node: HTMLElement): boolean => {
const elementCanBeScrolled = (node: HTMLElement, overflow: 'overflowX' | 'overflowY'): boolean => {
const styles = window.getComputedStyle(node);

return (
styles.overflowX !== 'hidden' && // not-not-scrollable
!(styles.overflowY === styles.overflowX && styles.overflowX === 'visible') // scrollable
// not-not-scrollable
styles[overflow] !== 'hidden' &&
// contains scroll inside self
!(styles.overflowY === styles.overflowX && !alwaysContainsScroll(node) && styles[overflow] === 'visible')
);
};

const elementCouldBeVScrolled = (node: HTMLElement): boolean => elementCanBeScrolled(node, 'overflowY');
const elementCouldBeHScrolled = (node: HTMLElement): boolean => elementCanBeScrolled(node, 'overflowX');

export const locationCouldBeScrolled = (axis: Axis, node: HTMLElement): boolean => {
let current = node;

Expand Down
15 changes: 15 additions & 0 deletions stories/text-area.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';

import ReactRemoveScroll from '../src/Combination';

export const TextAreaOverflow = () => (
<ReactRemoveScroll>
<div>
<textarea>{'hello'.repeat(500)}</textarea>
</div>
</ReactRemoveScroll>
);

export default {
title: 'textarea',
};

0 comments on commit af8fd75

Please sign in to comment.