Skip to content

Commit

Permalink
UI: InputVC/Mode, enforce options
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen committed Jan 20, 2025
1 parent 14e5000 commit 1892186
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public function nullControl(): NullControl;
* are not.
* rules:
* usage:
* 1: Exactly one Button MUST always be active/engaged.
* 1: Mode view control MUST contain more than one option.
* 2: Exactly one Button MUST always be active/engaged.
* accessibility:
* 1: The HTML container enclosing the buttons of the Mode View Control MUST carry the role-attribute "group".
* 2: The HTML container enclosing the buttons of the Mode View Control MUST set an aria-label describing the element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ public function __construct(
$keys = array_keys($options);
$this->checkArgListElements('options', $keys, 'string');
$this->checkArgListElements('options', $options, 'string');
if (count($options) < 2) {
throw new \InvalidArgumentException('ModeViewControls must contain more than one option.');
}
$this->setAdditionalTransformation(
$refinery->custom()->transformation(
static fn($v) => $v ?? array_keys($options)[0]
static fn($v) => $v ?? array_key_first($options)
)
);
parent::__construct($data_factory, $refinery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ protected function renderMode(Mode $component, RendererInterface $default_render

$container_submit_signal = $component->getOnChangeSignal();
$options = $component->getOptions();
$set_value = $component->getValue() ?? array_keys($options)[0];
$set_value = $component->getValue() ?? array_key_first($options);

$out = [];
foreach ($options as $opt_value => $opt_label) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="dropdown il-viewcontrol il-viewcontrol-fieldselection l-bar__element"<!-- BEGIN id --> id="{ID}" <!-- END id -->>
<button class="btn btn-ctrl dropdown-toggle" type="button" data-toggle="dropdown"<!-- BEGIN aria_label --> aria-label="{ARIA_LABEL}"<!-- END aria_label --> aria-haspopup="true" aria-expanded="false" aria-controls="{ID_MENU}"><span class="glyphicon-columnSelection"></span></button>

<ul id="{ID_MENU}" class="dropdown-menu">
<!-- BEGIN option -->
<li><input type="checkbox" value="{OPTION_VALUE}" id="{OPTION_ID}" {CHECKED} /> <label for="{OPTION_ID}">{OPTION_LABEL}</label> </li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="il-viewcontrol il-viewcontrol-pagination l-bar__element"<!-- BEGIN id --> id="{ID}" <!-- END id -->>
<div class="il-viewcontrol il-viewcontrol-pagination l-bar__element" id="{ID}">


<!-- BEGIN section_part -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="dropdown il-viewcontrol il-viewcontrol-sortation l-bar__element<!-- BEGIN disabled --> disabled<!-- END disabled -->"<!-- BEGIN id --> id="{ID}" <!-- END id -->>
<button class="btn btn-ctrl dropdown-toggle" type="button" data-toggle="dropdown"<!-- BEGIN aria_label --> aria-label="{ARIA_LABEL}"<!-- END aria_label --> aria-haspopup="true" aria-expanded="false" aria-controls="{ID_MENU}"><span class="glyphicon-sort"></span></button>

<ul id="{ID_MENU}" class="dropdown-menu">
<!-- BEGIN option -->
<li<!-- BEGIN selected --> class="selected"<!-- END selected -->>{OPTION}</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,17 @@ public function testViewControlModeRenderingOutsideContainer(): void
$this->expectException(\LogicException::class);
$this->buildVCFactory()->mode([])->getOnChangeSignal();
}

public function testViewControlModeWithoutOptions(): void
{
$this->expectException(\InvalidArgumentException::class);
$vc = $this->buildVCFactory()->mode([]);
}

public function testViewControlModeWithWrongOptions(): void
{
$this->expectException(\InvalidArgumentException::class);
$vc = $this->buildVCFactory()->mode([1,2,3]);
}

}

0 comments on commit 1892186

Please sign in to comment.