Skip to content

Commit adde00e

Browse files
authored
Merge pull request #2937 from pie-framework/fix/PD-5670
fix(drag-in-the-blank): autofocs for adding choice field, avoid brows…
2 parents d22f62b + a9d131d commit adde00e

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

packages/drag-in-the-blank/configure/src/choice.jsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { choiceIsEmpty } from './markupUtils';
88

99
const GripIcon = ({ style }) => (
1010
<span style={style}>
11-
<MoreVert style={{ margin: '0 -16px' }}/>
12-
<MoreVert/>
11+
<MoreVert style={{ margin: '0 -16px' }} />
12+
<MoreVert />
1313
</span>
1414
);
1515

@@ -32,7 +32,11 @@ const StyledChoice = styled('div', {
3232
cursor: 'grab',
3333
border: `1px solid ${error ? '#f44336' : '#C0C3CF'}`,
3434
'& img': {
35-
display: 'flex'
35+
display: 'flex',
36+
},
37+
// browser adds extra marrgin for p tags by default
38+
'& p': {
39+
margin: 0,
3640
},
3741
'& mjx-frac': {
3842
fontSize: '120% !important',
@@ -53,12 +57,7 @@ const StyledDeleteIcon = styled(Delete)(({ theme }) => ({
5357

5458
export const BlankContent = (props) => {
5559
const { choice, onClick, onRemoveChoice, error, instanceId, disabled } = props;
56-
const {
57-
attributes,
58-
listeners,
59-
setNodeRef,
60-
isDragging,
61-
} = useDraggable({
60+
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
6261
id: `choice-${choice.id}-${instanceId || 'default'}`,
6362
data: {
6463
type: 'drag-in-the-blank-choice',
@@ -67,7 +66,6 @@ export const BlankContent = (props) => {
6766
instanceId: instanceId,
6867
},
6968
disabled: disabled || choiceIsEmpty(choice),
70-
7169
});
7270

7371
const handleDragStart = (e) => {

packages/drag-in-the-blank/configure/src/choices.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { styled } from '@mui/material/styles';
77

88
import Choice from './choice';
99
import { choiceIsEmpty } from './markupUtils';
10-
import { renderMath } from "@pie-lib/math-rendering";
10+
import { renderMath } from '@pie-lib/math-rendering';
1111

1212
const StyledDesign = styled('div')(({ theme }) => ({
1313
display: 'flex',
@@ -150,9 +150,7 @@ export class Choices extends React.Component {
150150
} = this.props;
151151

152152
// find the maximum existing id and add 1 to generate the new id so we avoid duplicates
153-
const maxId = oldChoices.length > 0
154-
? Math.max(...oldChoices.map(choice => parseInt(choice.id, 10) || 0))
155-
: -1;
153+
const maxId = oldChoices.length > 0 ? Math.max(...oldChoices.map((choice) => parseInt(choice.id, 10) || 0)) : -1;
156154
const newId = `${maxId + 1}`;
157155

158156
this.setState(
@@ -243,6 +241,7 @@ export class Choices extends React.Component {
243241
>
244242
<EditableHtml
245243
ref={(ref) => (this.focusedNodeRef = ref)}
244+
autoFocus
246245
imageSupport={imageSupport}
247246
markup={choice.value}
248247
pluginProps={pluginProps}

0 commit comments

Comments
 (0)