public function groups(callable $groupCallback = null)
    {
        $groups = $this->groups;
        uasort($groups, [ $this, 'sortItemsByPriority' ]);

        $groupCallback = (isset($groupCallback) ? $groupCallback : $this->groupCallback);

        $groups = $this->finalizeFormGroups($groups);

        $i = 1;
        foreach ($groups as $group) {
            if ($groupCallback) {
                $groupCallback($group);
            }

            $GLOBALS['widget_template'] = $group->template();

            if (!$this->selectedFormGroup() && $this->isTabbable()) {
                $group->setIsHidden(false);
                if ($i > 1) {
                    $group->setIsHidden(true);
                }
            }
            $i++;

            yield $group;

            $GLOBALS['widget_template'] = '';
        }
    }