Skip to content

Commit

Permalink
FIX - Double-tap on select/multi-select inputs on mobile triggers unw…
Browse files Browse the repository at this point in the history
…anted tooltip mantinedev#6103
  • Loading branch information
Prasiddha-n committed Jun 13, 2024
1 parent 29f24e3 commit bf38469
Showing 1 changed file with 39 additions and 27 deletions.
66 changes: 39 additions & 27 deletions packages/@mantine/core/src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useRef } from 'react';
import { useMergeRefs } from '@floating-ui/react';
import {
Box,
BoxProps,
Expand Down Expand Up @@ -38,16 +40,16 @@ export type InputStylesNames = 'input' | 'wrapper' | 'section';
export type InputVariant = 'default' | 'filled' | 'unstyled';
export type InputCssVariables = {
wrapper:
| '--input-height'
| '--input-fz'
| '--input-radius'
| '--input-left-section-width'
| '--input-right-section-width'
| '--input-left-section-pointer-events'
| '--input-right-section-pointer-events'
| '--input-padding-y'
| '--input-margin-top'
| '--input-margin-bottom';
| '--input-height'
| '--input-fz'
| '--input-radius'
| '--input-left-section-width'
| '--input-right-section-width'
| '--input-left-section-pointer-events'
| '--input-right-section-pointer-events'
| '--input-padding-y'
| '--input-margin-top'
| '--input-margin-bottom';
};

export interface InputStylesCtx {
Expand Down Expand Up @@ -206,6 +208,9 @@ export const Input = polymorphicFactory<InputFactory>((_props, ref) => {
const ctx = useInputWrapperContext();
const stylesCtx: InputStylesCtx = { offsetBottom: ctx?.offsetBottom, offsetTop: ctx?.offsetTop };

const inputRef = useRef<HTMLInputElement>(null);
const inputMergedRef = useMergeRefs([ref, inputRef]);

const getStyles = useStyles<InputFactory>({
name: ['Input', __staticSelector],
props: __stylesApiProps || props,
Expand All @@ -223,12 +228,12 @@ export const Input = polymorphicFactory<InputFactory>((_props, ref) => {

const ariaAttributes = withAria
? {
required,
disabled,
'aria-invalid': !!error,
'aria-describedby': ctx?.describedBy,
id: ctx?.inputId || id,
}
required,
disabled,
'aria-invalid': !!error,
'aria-describedby': ctx?.describedBy,
id: ctx?.inputId || id,
}
: {};

return (
Expand Down Expand Up @@ -263,17 +268,24 @@ export const Input = polymorphicFactory<InputFactory>((_props, ref) => {
</div>
)}

<Box
component="input"
{...rest}
{...ariaAttributes}
ref={ref}
required={required}
mod={{ disabled, error: !!error && withErrorStyles }}
variant={variant}
__size={inputSize}
{...getStyles('input')}
/>
<Box onClick={() => {
if (!inputRef?.current?.readOnly) return;
inputRef?.current?.focus();
}}>
<Box
component="input"
{...rest}
{...ariaAttributes}
ref={inputMergedRef}
required={required}
mod={{ disabled, error: !!error && withErrorStyles }}
variant={variant}
__size={inputSize}
{...getStyles('input', {
style: { pointerEvents: inputRef?.current?.readOnly ? 'none' : 'auto' },
})}
/>
</Box>

{rightSection && (
<div
Expand Down

0 comments on commit bf38469

Please sign in to comment.