Skip to content

Commit

Permalink
Fix field input offset (#5726)
Browse files Browse the repository at this point in the history
Fix issue introduced in #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
  • Loading branch information
FelixMalfait authored Jun 4, 2024
1 parent cd9ac52 commit d964f65
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type GenericFieldContextType = {
basePathToShowPage?: string;
clearable?: boolean;
maxWidth?: number;
isCentered?: boolean;
};

export const FieldContext = createContext<GenericFieldContextType>(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const StyledClickableContainer = styled.div<{ readonly?: boolean }>`

type RecordInlineCellValueProps = Pick<
RecordInlineCellContainerProps,
| 'editModeContent'
| 'displayModeContent'
| 'customEditHotkeyScope'
| 'isDisplayModeContentEmpty'
| 'editModeContent'
| 'editModeContentOnly'
| 'isDisplayModeContentEmpty'
| 'isDisplayModeFixHeight'
| 'disableHoverEffect'
| 'readonly'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export const RecordShowContainer = ({
},
useUpdateRecord: useUpdateOneObjectRecordMutation,
hotkeyScope: InlineCellHotkeyScope.InlineCell,
isCentered: true,
}}
>
<RecordInlineCell readonly={isReadOnly} />
Expand Down

0 comments on commit d964f65

Please sign in to comment.