From 8e94d6057a0a20d74a109495a6d41c42b16094f6 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Sun, 26 Mar 2023 16:59:22 +0800 Subject: [PATCH] Add directionality fallback Refer to the element's direction when run in non-browser contexts. --- src/index.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index b6a5d64..d69aef5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -666,16 +666,17 @@ const getInputTextualFieldValue = ( inputEl: HTMLInputTextualElement, options = {} as GetInputTextualFieldValueOptions, ) => { - if ( - options.includeDirectionality - && typeof window !== 'undefined' - && typeof window.getComputedStyle === 'function' - && typeof (inputEl.dirName as unknown) === 'string' - ) { + if (options.includeDirectionality) { return new TextualValueString( inputEl.value, inputEl.dirName, - window.getComputedStyle(inputEl).direction || 'ltr', + ( + typeof window !== 'undefined' + && typeof window.getComputedStyle === 'function' + && typeof (inputEl.dirName as unknown) === 'string' + ? window.getComputedStyle(inputEl).direction || 'ltr' + : inputEl.dir + ), ); }