-
Notifications
You must be signed in to change notification settings - Fork 20
fix(plasma-web,plasma-b2c): Add useResizeObserver and fix behavior with resize in TextArea
#1186
base: master
Are you sure you want to change the base?
Conversation
Demo canvas app deployed! |
Documentation preview deployed! website: http://plasma.sberdevices.ru/pr-1186/ |
Codecov Report
@@ Coverage Diff @@
## master #1186 +/- ##
==========================================
- Coverage 89.04% 88.92% -0.13%
==========================================
Files 451 451
Lines 6189 6228 +39
Branches 1790 1797 +7
==========================================
+ Hits 5511 5538 +27
- Misses 677 689 +12
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
25105cc
to
f6d7c80
Compare
Demo canvas app deployed! |
Documentation preview deployed! website: http://plasma.sberdevices.ru/pr-1186/ |
f6d7c80
to
e0216ef
Compare
Demo canvas app deployed! |
Documentation preview deployed! website: http://plasma.sberdevices.ru/pr-1186/ |
|
||
return () => { | ||
/* istanbul ignore if: убираем проверку на рефы из покрытия */ | ||
if (!ref?.current) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а этот ифак зачем? у тебя же не дойдет сюда если рефа нет
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ага, я тоже так думал, но почему-то ts ругается
const [width, setWidth] = useState(0); | ||
const ref = useMemo(() => (outerRef && 'current' in outerRef ? outerRef : createRef<HTMLTextAreaElement>()), [ | ||
outerRef, | ||
]); | ||
|
||
useResizeObserver(ref, (currentElement) => { | ||
const { width: elementWidth } = currentElement.getBoundingClientRect(); | ||
|
||
setWidth(elementWidth); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не хочется это в отдельный хуй отнести? один и тот же код два раза встречается
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
кажется, что пока нет в этом необходимости, т.к. конкретно эти случаи очень специфичны и появляются в двух компонентах.
По-хорошему бы там вообще эти компоненты как-то в Core перетащить вместе с логикой, потому что они сильно похожи, но это уже задача на рефакторинг
) { | ||
const [width, setWidth] = useState(0); | ||
const ref = useMemo(() => (outerRef && 'current' in outerRef ? outerRef : createRef<HTMLTextAreaElement>()), [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не сломается, если сюда функцию передадут в outerRef
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не должно, как раз проверкой на 'current' in outerRef
я чекаю, штоб это было именно ref объектом
📦 Published PR as canary version:
Canary Versions
✨ Test out this PR locally via:
npm install @sberdevices/demo-canvas-app@0.72.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 npm install @sberdevices/plasma-b2c@1.57.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 npm install @sberdevices/plasma-core@1.56.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 npm install @sberdevices/plasma-icons@1.75.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 npm install @sberdevices/plasma-temple@1.57.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 npm install @sberdevices/plasma-ui@1.95.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 npm install @sberdevices/plasma-web@1.92.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 npm install @sberdevices/plasma-sb-utils@0.55.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 npm install @sberdevices/showcase@0.115.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 npm install @sberdevices/plasma-ui-docs@0.64.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 npm install @sberdevices/plasma-web-docs@0.50.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 npm install @sberdevices/plasma-website@0.47.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 # or yarn add @sberdevices/demo-canvas-app@0.72.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 yarn add @sberdevices/plasma-b2c@1.57.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 yarn add @sberdevices/plasma-core@1.56.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 yarn add @sberdevices/plasma-icons@1.75.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 yarn add @sberdevices/plasma-temple@1.57.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 yarn add @sberdevices/plasma-ui@1.95.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 yarn add @sberdevices/plasma-web@1.92.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 yarn add @sberdevices/plasma-sb-utils@0.55.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 yarn add @sberdevices/showcase@0.115.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 yarn add @sberdevices/plasma-ui-docs@0.64.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 yarn add @sberdevices/plasma-web-docs@0.50.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0 yarn add @sberdevices/plasma-website@0.47.0-canary.1186.5efcc7d7f9e2526d222828be46b19844e1f11d8e.0