Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"extends": [
"plugin:github/internal",
"plugin:github/recommended",
"plugin:github/browser"
"plugin:github/browser",
"plugin:github/typescript"
]
}
20 changes: 12 additions & 8 deletions src/index.js → src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
export default function autosize(textarea, {viewportMarginBottom = 100} = {}) {
let previousValue = null
interface Subscription {
unsubscribe(): void
}

export default function autosize(textarea: HTMLTextAreaElement, {viewportMarginBottom = 100} = {}): Subscription {
let previousValue: string | null = null
let isUserResized = false

let x
let y
let height
let x: number
let y: number
let height: string

function onUserResize(event) {
function onUserResize(event: MouseEvent) {
if (x !== event.clientX || y !== event.clientY) {
const newHeight = textarea.style.height
if (height && height !== newHeight) {
Expand All @@ -30,10 +34,10 @@ export default function autosize(textarea, {viewportMarginBottom = 100} = {}) {

while (el !== document.body && el !== null) {
offsetTop += el.offsetTop || 0
el = el.offsetParent
el = el.offsetParent as HTMLTextAreaElement
}

const top = offsetTop - document.defaultView.pageYOffset
const top = offsetTop - document.defaultView!.pageYOffset
const bottom = documentElement.clientHeight - (top + textarea.offsetHeight)
return {top, bottom}
}
Expand Down
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
"declaration": true,
"outDir": "dist",
"removeComments": true,
"preserveConstEnums": true,
"allowJs": true
"preserveConstEnums": true
},
"files": [
"src/index.js"
"src/index.ts"
]
}