@pie-element/multiple-choice 9.16.4 → 9.16.5-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/module/print.js CHANGED
@@ -12239,7 +12239,7 @@ const inputStyles = {
12239
12239
  }
12240
12240
  };
12241
12241
  const StyledCheckbox = styles$b.withStyles(inputStyles)(props => {
12242
- const {correctness, classes, checked, onChange, disabled, value, id} = props;
12242
+ const {correctness, classes, checked, onChange, disabled, value, id, onKeyDown, inputRef} = props;
12243
12243
  const key = k => correctness ? `${correctness}-${k}` : k;
12244
12244
  const resolved = {
12245
12245
  root: classes[key('root')],
@@ -12254,7 +12254,9 @@ const StyledCheckbox = styles$b.withStyles(inputStyles)(props => {
12254
12254
  };
12255
12255
  return React$4.createElement(Checkbox, {
12256
12256
  id: id,
12257
+ inputRef: inputRef,
12257
12258
  'aria-checked': checked,
12259
+ onKeyDown: onKeyDown,
12258
12260
  focusVisibleClassName: checked ? classes.focusVisibleChecked : classes.focusVisibleUnchecked,
12259
12261
  disableRipple: true,
12260
12262
  ...miniProps,
@@ -12301,7 +12303,7 @@ const StyledRadio = styles$b.withStyles(inputStyles)(props => {
12301
12303
  __self: undefined,
12302
12304
  __source: {
12303
12305
  fileName: _jsxFileName$3,
12304
- lineNumber: 165
12306
+ lineNumber: 167
12305
12307
  }
12306
12308
  });
12307
12309
  });
@@ -12320,6 +12322,7 @@ class ChoiceInput extends React$4.Component {
12320
12322
  value: PropTypes$3.string.isRequired,
12321
12323
  classes: PropTypes$3.object,
12322
12324
  className: PropTypes$3.string,
12325
+ tagName: PropTypes$3.string,
12323
12326
  hideTick: PropTypes$3.bool,
12324
12327
  isEvaluateMode: PropTypes$3.bool,
12325
12328
  choicesLayout: PropTypes$3.oneOf(['vertical', 'grid', 'horizontal']),
@@ -12335,6 +12338,7 @@ class ChoiceInput extends React$4.Component {
12335
12338
  }
12336
12339
  constructor(props) {
12337
12340
  super(props);
12341
+ ChoiceInput.prototype.__init.call(this);
12338
12342
  this.onToggleChoice = this.onToggleChoice.bind(this);
12339
12343
  this.choiceId = this.generateChoiceId();
12340
12344
  this.descId = `${this.choiceId}-desc`;
@@ -12345,6 +12349,28 @@ class ChoiceInput extends React$4.Component {
12345
12349
  generateChoiceId() {
12346
12350
  return 'choice-' + (Math.random() * 10000).toFixed();
12347
12351
  }
12352
+ __init() {
12353
+ this.handleKeyDown = event => {
12354
+ const {choiceMode} = this.props;
12355
+ if (choiceMode !== 'checkbox') return;
12356
+ const isArrowDown = event.key === 'ArrowDown';
12357
+ const isArrowUp = event.key === 'ArrowUp';
12358
+ if (!isArrowDown && !isArrowUp) return;
12359
+ event.preventDefault();
12360
+ const currentEl = document.getElementById(this.choiceId);
12361
+ if (!currentEl) return;
12362
+ const fieldset = currentEl.closest('fieldset');
12363
+ if (!fieldset) return;
12364
+ const groupCheckboxes = Array.from(fieldset.querySelectorAll('input[type="checkbox"]'));
12365
+ const currentIndex = groupCheckboxes.findIndex(el => el === currentEl);
12366
+ if (currentIndex === -1) return;
12367
+ const nextIndex = isArrowDown ? currentIndex + 1 : currentIndex - 1;
12368
+ const nextEl = groupCheckboxes[nextIndex];
12369
+ if (nextEl) {
12370
+ nextEl.focus();
12371
+ }
12372
+ };
12373
+ }
12348
12374
  render() {
12349
12375
  const {choiceMode, disabled, displayKey, feedback, label, correctness, classes, className, rationale, hideTick, isEvaluateMode, choicesLayout, value, checked, tagName, isSelectionButtonBelow} = this.props;
12350
12376
  const Tag = choiceMode === 'checkbox' ? StyledCheckbox : StyledRadio;
@@ -12359,7 +12385,7 @@ class ChoiceInput extends React$4.Component {
12359
12385
  __self: this,
12360
12386
  __source: {
12361
12387
  fileName: _jsxFileName$3,
12362
- lineNumber: 255
12388
+ lineNumber: 289
12363
12389
  }
12364
12390
  }, displayKey, ".", '\u00A0', React$4.createElement(PreviewPrompt$1, {
12365
12391
  className: "label",
@@ -12368,7 +12394,7 @@ class ChoiceInput extends React$4.Component {
12368
12394
  __self: this,
12369
12395
  __source: {
12370
12396
  fileName: _jsxFileName$3,
12371
- lineNumber: 257
12397
+ lineNumber: 291
12372
12398
  }
12373
12399
  })) : React$4.createElement(PreviewPrompt$1, {
12374
12400
  className: "label",
@@ -12377,7 +12403,7 @@ class ChoiceInput extends React$4.Component {
12377
12403
  __self: this,
12378
12404
  __source: {
12379
12405
  fileName: _jsxFileName$3,
12380
- lineNumber: 260
12406
+ lineNumber: 294
12381
12407
  }
12382
12408
  }));
12383
12409
  const screenReaderLabel = React$4.createElement('span', {
@@ -12386,7 +12412,7 @@ class ChoiceInput extends React$4.Component {
12386
12412
  __self: this,
12387
12413
  __source: {
12388
12414
  fileName: _jsxFileName$3,
12389
- lineNumber: 266
12415
+ lineNumber: 300
12390
12416
  }
12391
12417
  }, choiceMode === 'checkbox' ? 'Checkbox to select the answer below' : 'Radio button to select the answer below');
12392
12418
  const tagProps = {
@@ -12397,6 +12423,7 @@ class ChoiceInput extends React$4.Component {
12397
12423
  value,
12398
12424
  id: this.choiceId,
12399
12425
  onChange: this.onToggleChoice,
12426
+ onKeyDown: this.handleKeyDown,
12400
12427
  'aria-describedby': this.descId
12401
12428
  };
12402
12429
  const hasMathOrImage = typeof label === 'string' && (label.includes('<math') || label.includes('\\(') || label.includes('\\[') || label.includes('<img') || label.includes('data-latex') || label.includes('data-raw') || label.includes('<mjx-container'));
@@ -12405,7 +12432,7 @@ class ChoiceInput extends React$4.Component {
12405
12432
  __self: this,
12406
12433
  __source: {
12407
12434
  fileName: _jsxFileName$3,
12408
- lineNumber: 293
12435
+ lineNumber: 328
12409
12436
  }
12410
12437
  }, hasMathOrImage && screenReaderLabel, React$4.createElement(Tag, {
12411
12438
  ...tagProps,
@@ -12415,14 +12442,15 @@ class ChoiceInput extends React$4.Component {
12415
12442
  __self: this,
12416
12443
  __source: {
12417
12444
  fileName: _jsxFileName$3,
12418
- lineNumber: 295
12445
+ lineNumber: 330
12419
12446
  }
12420
12447
  }), displayKey ? `${displayKey}.` : '') : React$4.createElement(React$4.Fragment, null, hasMathOrImage && screenReaderLabel, React$4.createElement(Tag, {
12421
12448
  ...tagProps,
12449
+ inputRef: this.props.autoFocusRef,
12422
12450
  __self: this,
12423
12451
  __source: {
12424
12452
  fileName: _jsxFileName$3,
12425
- lineNumber: 301
12453
+ lineNumber: 336
12426
12454
  }
12427
12455
  }));
12428
12456
  return React$4.createElement('div', {
@@ -12430,28 +12458,28 @@ class ChoiceInput extends React$4.Component {
12430
12458
  __self: this,
12431
12459
  __source: {
12432
12460
  fileName: _jsxFileName$3,
12433
- lineNumber: 306
12461
+ lineNumber: 341
12434
12462
  }
12435
12463
  }, React$4.createElement('div', {
12436
12464
  className: classes.row,
12437
12465
  __self: this,
12438
12466
  __source: {
12439
12467
  fileName: _jsxFileName$3,
12440
- lineNumber: 307
12468
+ lineNumber: 342
12441
12469
  }
12442
12470
  }, !hideTick && isEvaluateMode && React$4.createElement(FeedbackTick$1, {
12443
12471
  correctness: correctness,
12444
12472
  __self: this,
12445
12473
  __source: {
12446
12474
  fileName: _jsxFileName$3,
12447
- lineNumber: 308
12475
+ lineNumber: 343
12448
12476
  }
12449
12477
  }), React$4.createElement('div', {
12450
12478
  className: classNames$2(holderClassNames, 'checkbox-holder'),
12451
12479
  __self: this,
12452
12480
  __source: {
12453
12481
  fileName: _jsxFileName$3,
12454
- lineNumber: 309
12482
+ lineNumber: 344
12455
12483
  }
12456
12484
  }, React$4.createElement(StyledFormControlLabel, {
12457
12485
  label: choicelabel,
@@ -12462,7 +12490,7 @@ class ChoiceInput extends React$4.Component {
12462
12490
  __self: this,
12463
12491
  __source: {
12464
12492
  fileName: _jsxFileName$3,
12465
- lineNumber: 310
12493
+ lineNumber: 345
12466
12494
  }
12467
12495
  }))), rationale && React$4.createElement(PreviewPrompt$1, {
12468
12496
  className: "rationale",
@@ -12471,7 +12499,7 @@ class ChoiceInput extends React$4.Component {
12471
12499
  __self: this,
12472
12500
  __source: {
12473
12501
  fileName: _jsxFileName$3,
12474
- lineNumber: 319
12502
+ lineNumber: 354
12475
12503
  }
12476
12504
  }), React$4.createElement(Feedback, {
12477
12505
  feedback: feedback,
@@ -12479,7 +12507,7 @@ class ChoiceInput extends React$4.Component {
12479
12507
  __self: this,
12480
12508
  __source: {
12481
12509
  fileName: _jsxFileName$3,
12482
- lineNumber: 320
12510
+ lineNumber: 355
12483
12511
  }
12484
12512
  }));
12485
12513
  }
@@ -12508,7 +12536,7 @@ class Choice extends React$3.Component {
12508
12536
  };
12509
12537
  }
12510
12538
  render() {
12511
- const {choice, index, choicesLength, showCorrect, isEvaluateMode, choiceMode, disabled, checked, correctness, displayKey, classes, choicesLayout, gridColumns, isSelectionButtonBelow, selectedAnswerBackgroundColor, tagName} = this.props;
12539
+ const {choice, index, choicesLength, showCorrect, isEvaluateMode, choiceMode, disabled, checked, correctness, displayKey, classes, choicesLayout, gridColumns, isSelectionButtonBelow, selectedAnswerBackgroundColor, autoFocusRef, tagName} = this.props;
12512
12540
  const choiceClass = 'choice' + (index === choicesLength - 1 ? ' last' : '');
12513
12541
  const feedback = !isEvaluateMode || showCorrect ? '' : choice.feedback;
12514
12542
  const choiceProps = {
@@ -12541,15 +12569,16 @@ class Choice extends React$3.Component {
12541
12569
  __self: this,
12542
12570
  __source: {
12543
12571
  fileName: _jsxFileName$2,
12544
- lineNumber: 67
12572
+ lineNumber: 68
12545
12573
  }
12546
12574
  }, React$3.createElement(ChoiceInput$1, {
12547
12575
  ...choiceProps,
12548
12576
  className: names,
12577
+ autoFocusRef: autoFocusRef,
12549
12578
  __self: this,
12550
12579
  __source: {
12551
12580
  fileName: _jsxFileName$2,
12552
- lineNumber: 68
12581
+ lineNumber: 69
12553
12582
  }
12554
12583
  }));
12555
12584
  }
@@ -12572,7 +12601,8 @@ Choice.propTypes = {
12572
12601
  gridColumns: PropTypes$2.string,
12573
12602
  selectedAnswerBackgroundColor: PropTypes$2.string,
12574
12603
  tagName: PropTypes$2.string,
12575
- isSelectionButtonBelow: PropTypes$2.bool
12604
+ isSelectionButtonBelow: PropTypes$2.bool,
12605
+ autoFocusRef: PropTypes$2.object
12576
12606
  };
12577
12607
  var StyledChoice = styles$b.withStyles(theme => ({
12578
12608
  choice: {
@@ -12600,6 +12630,27 @@ const {color: color} = _dll_pie_lib__pie_toolbox_render_ui;
12600
12630
  const {Collapsible: Collapsible} = _dll_pie_lib__pie_toolbox_render_ui;
12601
12631
  const {PreviewPrompt: PreviewPrompt} = _dll_pie_lib__pie_toolbox_render_ui;
12602
12632
  const _jsxFileName$1 = "/home/circleci/repo/packages/multiple-choice/src/multiple-choice.jsx";
12633
+ function _optionalChain(ops) {
12634
+ let lastAccessLHS = undefined;
12635
+ let value = ops[0];
12636
+ let i = 1;
12637
+ while (i < ops.length) {
12638
+ const op = ops[i];
12639
+ const fn = ops[i + 1];
12640
+ i += 2;
12641
+ if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) {
12642
+ return undefined;
12643
+ }
12644
+ if (op === 'access' || op === 'optionalAccess') {
12645
+ lastAccessLHS = value;
12646
+ value = fn(value);
12647
+ } else if (op === 'call' || op === 'optionalCall') {
12648
+ value = fn((...args) => value.call(lastAccessLHS, ...args));
12649
+ lastAccessLHS = undefined;
12650
+ }
12651
+ }
12652
+ return value;
12653
+ }
12603
12654
  const {translator} = Translator;
12604
12655
  const styles$1 = theme => ({
12605
12656
  main: {
@@ -12690,11 +12741,13 @@ class MultipleChoice extends React$2.Component {
12690
12741
  MultipleChoice.prototype.__init.call(this);
12691
12742
  MultipleChoice.prototype.__init2.call(this);
12692
12743
  MultipleChoice.prototype.__init3.call(this);
12744
+ MultipleChoice.prototype.__init4.call(this);
12693
12745
  this.state = {
12694
12746
  showCorrect: this.props.alwaysShowCorrect || false,
12695
12747
  maxSelectionsErrorState: false
12696
12748
  };
12697
12749
  this.onToggle = this.onToggle.bind(this);
12750
+ this.firstInputRef = React$2.createRef();
12698
12751
  }
12699
12752
  isSelected(value) {
12700
12753
  const sessionValue = this.props.session && this.props.session.value;
@@ -12799,17 +12852,29 @@ class MultipleChoice extends React$2.Component {
12799
12852
  __self: this,
12800
12853
  __source: {
12801
12854
  fileName: _jsxFileName$1,
12802
- lineNumber: 219
12855
+ lineNumber: 220
12803
12856
  }
12804
12857
  }, "Multiple Choice Question") : React$2.createElement('h2', {
12805
12858
  className: classes.srOnly,
12806
12859
  __self: this,
12807
12860
  __source: {
12808
12861
  fileName: _jsxFileName$1,
12809
- lineNumber: 221
12862
+ lineNumber: 222
12810
12863
  }
12811
12864
  }, "Multiple Select Question");
12812
12865
  }
12866
+ __init4() {
12867
+ this.handleGroupFocus = e => {
12868
+ const fieldset = e.currentTarget;
12869
+ const activeEl = document.activeElement;
12870
+ if (fieldset.contains(activeEl) && activeEl !== fieldset) {
12871
+ return;
12872
+ }
12873
+ if (_optionalChain([this, 'access', _3 => _3.firstInputRef, 'optionalAccess', _4 => _4.current])) {
12874
+ this.firstInputRef.current.focus();
12875
+ }
12876
+ };
12877
+ }
12813
12878
  render() {
12814
12879
  const {mode, disabled, className, choices = [], choiceMode, gridColumns, partLabel, prompt, responseCorrect, teacherInstructions, classes, alwaysShowCorrect, animationsDisabled, language, isSelectionButtonBelow, minSelections, maxSelections, autoplayAudioEnabled, session, customAudioButton} = this.props;
12815
12880
  const {showCorrect, maxSelectionsErrorState} = this.state;
@@ -12827,7 +12892,7 @@ class MultipleChoice extends React$2.Component {
12827
12892
  __self: this,
12828
12893
  __source: {
12829
12894
  fileName: _jsxFileName$1,
12830
- lineNumber: 255
12895
+ lineNumber: 269
12831
12896
  }
12832
12897
  });
12833
12898
  const getMultipleChoiceMinSelectionErrorMessage = () => {
@@ -12855,21 +12920,21 @@ class MultipleChoice extends React$2.Component {
12855
12920
  __self: this,
12856
12921
  __source: {
12857
12922
  fileName: _jsxFileName$1,
12858
- lineNumber: 278
12923
+ lineNumber: 296
12859
12924
  }
12860
12925
  }, partLabel && React$2.createElement('h3', {
12861
12926
  className: classes.partLabel,
12862
12927
  __self: this,
12863
12928
  __source: {
12864
12929
  fileName: _jsxFileName$1,
12865
- lineNumber: 279
12930
+ lineNumber: 297
12866
12931
  }
12867
12932
  }, partLabel), this.renderHeading(), teacherInstructions && React$2.createElement('div', {
12868
12933
  className: classes.teacherInstructions,
12869
12934
  __self: this,
12870
12935
  __source: {
12871
12936
  fileName: _jsxFileName$1,
12872
- lineNumber: 284
12937
+ lineNumber: 302
12873
12938
  }
12874
12939
  }, !animationsDisabled ? React$2.createElement(Collapsible, {
12875
12940
  labels: {
@@ -12879,16 +12944,17 @@ class MultipleChoice extends React$2.Component {
12879
12944
  __self: this,
12880
12945
  __source: {
12881
12946
  fileName: _jsxFileName$1,
12882
- lineNumber: 286
12947
+ lineNumber: 304
12883
12948
  }
12884
12949
  }, teacherInstructionsDiv) : teacherInstructionsDiv), React$2.createElement('fieldset', {
12885
12950
  tabIndex: 0,
12886
12951
  className: classes.fieldset,
12952
+ onFocus: this.handleGroupFocus,
12887
12953
  role: choiceMode === 'radio' ? 'radiogroup' : 'group',
12888
12954
  __self: this,
12889
12955
  __source: {
12890
12956
  fileName: _jsxFileName$1,
12891
- lineNumber: 300
12957
+ lineNumber: 318
12892
12958
  }
12893
12959
  }, React$2.createElement(PreviewPrompt, {
12894
12960
  className: "prompt",
@@ -12900,7 +12966,7 @@ class MultipleChoice extends React$2.Component {
12900
12966
  __self: this,
12901
12967
  __source: {
12902
12968
  fileName: _jsxFileName$1,
12903
- lineNumber: 301
12969
+ lineNumber: 324
12904
12970
  }
12905
12971
  }), !alwaysShowCorrect && React$2.createElement(CorrectAnswerToggle, {
12906
12972
  show: showCorrectAnswerToggle,
@@ -12910,7 +12976,7 @@ class MultipleChoice extends React$2.Component {
12910
12976
  __self: this,
12911
12977
  __source: {
12912
12978
  fileName: _jsxFileName$1,
12913
- lineNumber: 311
12979
+ lineNumber: 334
12914
12980
  }
12915
12981
  }), React$2.createElement('div', {
12916
12982
  className: classNames({
@@ -12921,9 +12987,10 @@ class MultipleChoice extends React$2.Component {
12921
12987
  __self: this,
12922
12988
  __source: {
12923
12989
  fileName: _jsxFileName$1,
12924
- lineNumber: 319
12990
+ lineNumber: 342
12925
12991
  }
12926
12992
  }, choices.map((choice, index) => React$2.createElement(StyledChoice, {
12993
+ autoFocusRef: index === 0 ? this.firstInputRef : null,
12927
12994
  choicesLayout: this.props.choicesLayout,
12928
12995
  selectedAnswerBackgroundColor: this.props.selectedAnswerBackgroundColor,
12929
12996
  gridColumns: gridColumns,
@@ -12945,21 +13012,21 @@ class MultipleChoice extends React$2.Component {
12945
13012
  __self: this,
12946
13013
  __source: {
12947
13014
  fileName: _jsxFileName$1,
12948
- lineNumber: 327
13015
+ lineNumber: 350
12949
13016
  }
12950
13017
  })))), choiceMode === 'checkbox' && selections < minSelections && React$2.createElement('div', {
12951
13018
  className: classes.errorText,
12952
13019
  __self: this,
12953
13020
  __source: {
12954
13021
  fileName: _jsxFileName$1,
12955
- lineNumber: 352
13022
+ lineNumber: 376
12956
13023
  }
12957
13024
  }, getMultipleChoiceMinSelectionErrorMessage()), choiceMode === 'checkbox' && maxSelectionsErrorState && React$2.createElement('div', {
12958
13025
  className: classes.errorText,
12959
13026
  __self: this,
12960
13027
  __source: {
12961
13028
  fileName: _jsxFileName$1,
12962
- lineNumber: 357
13029
+ lineNumber: 379
12963
13030
  }
12964
13031
  }, translator.t(`translation:multipleChoice:maxSelections_${maxSelections === 1 ? 'one' : 'other'}`, {
12965
13032
  lng: language,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pie-element/multiple-choice",
3
3
  "repository": "pie-framework/pie-elements",
4
- "version": "9.16.4",
4
+ "version": "9.16.5-next.3+fff627751",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -19,7 +19,7 @@
19
19
  "react-test-renderer": "^16.3.2",
20
20
  "react-transition-group": "^2.3.1"
21
21
  },
22
- "gitHead": "e54e56916867a5176bc13b46b21816164f4792ea",
22
+ "gitHead": "fff62775142fc637ffef1f68660901ade504d597",
23
23
  "scripts": {
24
24
  "postpublish": "../../scripts/postpublish"
25
25
  },