-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Textarea: resize immediately upon receiving resize event #3463
Conversation
🦋 Changeset detectedLatest commit: c4243fc The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Storybook demo6d4006631 | 91 komponenter | 135 stories |
Thinking this could be solved via CSS set on the parent of the element maybe? This could be due to when the resize event is fired, and it happens after the element is added to the dom => gets resized to the new size? https://github.com/navikt/aksel/blob/main/@navikt/core/react/src/util/TextareaAutoSize.tsx#L187 |
The solution is to run Here is an improved version of our current function in case we want to continue using that: "use client";
// https://github.com/mui/material-ui/blob/master/packages/mui-utils/src/debounce.js
export default function debounce<T extends unknown[]>(
func: (...args: T) => void,
wait = 166,
leading = false,
) {
let timeout: ReturnType<typeof setTimeout> | undefined;
function debounced(this: any, ...args: T) {
const later = () => {
timeout = undefined;
func.apply(this, args);
};
if (!timeout && leading) {
later();
}
clearTimeout(timeout);
timeout = setTimeout(later, wait);
}
debounced.clear = () => {
clearTimeout(timeout);
};
return debounced;
} I think we should add a comment in TextareaAutoSize.tsx explaining why this is needed. Something like this:
|
Co-authored-by: Halvor Haugan <halvor.haugan@nav.no>
Description
got feedback on buggy behaviour of textarea "jumping" inside a modal (upon opening).
Component Checklist 📝
@navikt/core/css/config/_mappings.js
)@navikt/core/css/tokens.json
)@navikt/aksel-stylelint/src/deprecations.ts
)@navikt/core/react/src/index.ts
and@navikt/core/react/package.json
)@navikt/core/css/index.css
)<Component>: <gitmoji?> <Text>.
E.g. "Button: ✨ Add feature xyz.")