From a9d131dba7c08a9bca02ad266b1d913bbb1ef5a2 Mon Sep 17 00:00:00 2001 From: arimieandreea Date: Wed, 4 Mar 2026 10:04:03 +0200 Subject: [PATCH] fix(drag-in-the-blank): autofocs for adding choice field, avoid browser extraspaces for p tags PD-5670 --- .../drag-in-the-blank/configure/src/choice.jsx | 18 ++++++++---------- .../configure/src/choices.jsx | 7 +++---- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/drag-in-the-blank/configure/src/choice.jsx b/packages/drag-in-the-blank/configure/src/choice.jsx index 197e1ed2a9..c4836b5043 100644 --- a/packages/drag-in-the-blank/configure/src/choice.jsx +++ b/packages/drag-in-the-blank/configure/src/choice.jsx @@ -8,8 +8,8 @@ import { choiceIsEmpty } from './markupUtils'; const GripIcon = ({ style }) => ( - - + + ); @@ -32,7 +32,11 @@ const StyledChoice = styled('div', { cursor: 'grab', border: `1px solid ${error ? '#f44336' : '#C0C3CF'}`, '& img': { - display: 'flex' + display: 'flex', + }, + // browser adds extra marrgin for p tags by default + '& p': { + margin: 0, }, '& mjx-frac': { fontSize: '120% !important', @@ -53,12 +57,7 @@ const StyledDeleteIcon = styled(Delete)(({ theme }) => ({ export const BlankContent = (props) => { const { choice, onClick, onRemoveChoice, error, instanceId, disabled } = props; - const { - attributes, - listeners, - setNodeRef, - isDragging, - } = useDraggable({ + const { attributes, listeners, setNodeRef, isDragging } = useDraggable({ id: `choice-${choice.id}-${instanceId || 'default'}`, data: { type: 'drag-in-the-blank-choice', @@ -67,7 +66,6 @@ export const BlankContent = (props) => { instanceId: instanceId, }, disabled: disabled || choiceIsEmpty(choice), - }); const handleDragStart = (e) => { diff --git a/packages/drag-in-the-blank/configure/src/choices.jsx b/packages/drag-in-the-blank/configure/src/choices.jsx index fa571af116..776b7404e7 100644 --- a/packages/drag-in-the-blank/configure/src/choices.jsx +++ b/packages/drag-in-the-blank/configure/src/choices.jsx @@ -7,7 +7,7 @@ import { styled } from '@mui/material/styles'; import Choice from './choice'; import { choiceIsEmpty } from './markupUtils'; -import { renderMath } from "@pie-lib/math-rendering"; +import { renderMath } from '@pie-lib/math-rendering'; const StyledDesign = styled('div')(({ theme }) => ({ display: 'flex', @@ -150,9 +150,7 @@ export class Choices extends React.Component { } = this.props; // find the maximum existing id and add 1 to generate the new id so we avoid duplicates - const maxId = oldChoices.length > 0 - ? Math.max(...oldChoices.map(choice => parseInt(choice.id, 10) || 0)) - : -1; + const maxId = oldChoices.length > 0 ? Math.max(...oldChoices.map((choice) => parseInt(choice.id, 10) || 0)) : -1; const newId = `${maxId + 1}`; this.setState( @@ -243,6 +241,7 @@ export class Choices extends React.Component { > (this.focusedNodeRef = ref)} + autoFocus imageSupport={imageSupport} markup={choice.value} pluginProps={pluginProps}