-
-
Notifications
You must be signed in to change notification settings - Fork 228
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
Positioning issues with Inputs when the keyboard changes of type #521
Comments
I found a solution, i edited the mjs version and edited the onvisualviewportchange function to this and now it works flawlessly.
|
@Fefedu973 Since the contents of that useEffect look different to the version i have, it looks like all you've changed is the threshold to detect if the keyboard is open? if (Math.abs(previousDiffFromInitial.current - diffFromInitial) > 60) {
keyboardIsOpen.current = !keyboardIsOpen.current;
} vs if (Math.abs(previousDiffFromInitial.current - diffFromInitial) > 20) {
keyboardIsOpen.current = !keyboardIsOpen.current;
} |
on android firefox: my solution was to anchor an element to all edges of the screen then flex align the drawercontent to the edges/corners I want: import cn from 'classnames';
import tv from 'tailwind-variants';
const DrawerFrameStyles = tv({
base: ['bg-background-base shadow-lg', 'max-w-full ', 'flex flex-col'],
variants: {
tone: {
primary: ['text-text-base bg-background-overlay'],
},
rounded: { true: ['rounded-t-[10px] rounded-b-[10px]'] },
size: {
sm: ['w-full md:w-[320px]'],
md: ['w-full md:w-[480px]'],
lg: ['w-full md:w-[640px]'],
xl: ['w-full md:w-[800px]'],
},
},
defaultVariants: {
size: 'md',
tone: 'primary',
rounded: true,
},
});
const DrawerFrame = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement> &
VariantProps<typeof DrawerFrameStyles>) => {
const styles = DrawerFrameStyles(props);
return (
<div
className={cn(styles, className)}
{...props}
/>
);
};
DrawerFrame.displayName = 'DrawerFrame';
const DrawerAnchorStyles = tv({
base: 'drawer-anchored top-0 bottom-0 left-0 right-0 flex flex-col max-h-screen',
variants: {
anchor: {
bottomleft: ['justify-end items-start'],
bottomright: ['justify-end items-end'],
bottom: ['justify-end items-center'],
topleft: ['justify-start items-start'],
topright: ['justify-start items-end'],
top: ['justify-start items-center'],
left: ['justify-center items-start'],
right: ['justify-center items-end'],
},
},
defaultVariants: {
anchor: 'bottomright',
},
});
const DrawerContent = forwardRef<
React.ElementRef<typeof DrawerPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content> &
VariantProps<typeof DrawerFrameStyles> &
VariantProps<typeof DrawerAnchorStyles>
>(({ className, children, anchor, tone, rounded, size, ...props }, ref) => {
const styles = DrawerAnchorStyles({ anchor });
return (
<DrawerPortal>
<DrawerOverlay />
<Box className={cn('fixed z-50 ', styles, className)}>
<DrawerPrimitive.Content
ref={ref}
{...props}
>
<DrawerFrame
tone={tone}
rounded={rounded}
size={size}
className={cn('overflow-y-auto max-h-screen', className)}
{...props}
>
<DrawerHandle
edge={(anchor.startsWith('bottom') && 'top') || 'bottom'}
/>
{children}
</DrawerFrame>
</DrawerPrimitive.Content>
</Box>
</DrawerPortal>
);
});
DrawerContent.displayName = 'DrawerContent'; Now when focused, inputs are correctly moved into the screen, and when blurred the drawer correctly repositions. Additionally, drawers whose content is too tall for the screen can be scrolled to. |
In an input when the keyboard changes size there is an issue where it is not handled well.
See:
https://github.com/user-attachments/assets/d4d5e69f-a958-4c2a-8c79-a410d741cd9e
The text was updated successfully, but these errors were encountered: