Fix field input offset (#5726)

Fix issue introduced in https://github.com/twentyhq/twenty/pull/5426

It's not a beautiful solution. Maybe one day we should have a dedicated
component for title but it also comes with downsides (lot of code to
copy paste, such as "esc" to leave field, copy button, etc.). This one
doesn't create less debt in my opinion. Once we have the layout/widget
system we might have a dedicated widget type and the right abstraction
layers
This commit is contained in:
Félix Malfait 2024-06-04 11:44:54 +02:00 committed by GitHub
parent cd9ac529a5
commit d964f656f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 6 deletions

View File

@ -29,6 +29,7 @@ export type GenericFieldContextType = {
basePathToShowPage?: string;
clearable?: boolean;
maxWidth?: number;
isCentered?: boolean;
};
export const FieldContext = createContext<GenericFieldContextType>(

View File

@ -1,8 +1,11 @@
import { useContext } from 'react';
import { createPortal } from 'react-dom';
import styled from '@emotion/styled';
import { autoUpdate, flip, offset, useFloating } from '@floating-ui/react';
const StyledInlineCellEditModeContainer = styled.div<RecordInlineCellEditModeProps>`
import { FieldContext } from '@/object-record/record-field/contexts/FieldContext';
const StyledInlineCellEditModeContainer = styled.div`
align-items: center;
display: flex;
@ -29,12 +32,22 @@ type RecordInlineCellEditModeProps = {
export const RecordInlineCellEditMode = ({
children,
}: RecordInlineCellEditModeProps) => {
const { isCentered } = useContext(FieldContext);
const { refs, floatingStyles } = useFloating({
placement: isCentered ? undefined : 'right-start',
middleware: [
flip(),
offset({
mainAxis: -30,
}),
offset(
isCentered
? {
mainAxis: -30,
}
: {
crossAxis: -4,
mainAxis: -4,
},
),
],
whileElementsMounted: autoUpdate,
});

View File

@ -23,11 +23,11 @@ const StyledClickableContainer = styled.div<{ readonly?: boolean }>`
type RecordInlineCellValueProps = Pick<
RecordInlineCellContainerProps,
| 'editModeContent'
| 'displayModeContent'
| 'customEditHotkeyScope'
| 'isDisplayModeContentEmpty'
| 'editModeContent'
| 'editModeContentOnly'
| 'isDisplayModeContentEmpty'
| 'isDisplayModeFixHeight'
| 'disableHoverEffect'
| 'readonly'

View File

@ -168,6 +168,7 @@ export const RecordShowContainer = ({
},
useUpdateRecord: useUpdateOneObjectRecordMutation,
hotkeyScope: InlineCellHotkeyScope.InlineCell,
isCentered: true,
}}
>
<RecordInlineCell readonly={isReadOnly} />