@pie-element/multiple-choice 9.16.5-next.0 → 9.16.5-next.6

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