diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md
index c5628cd234..7956245d64 100644
--- a/framework/CHANGELOG.md
+++ b/framework/CHANGELOG.md
@@ -42,6 +42,7 @@ Yii Framework 2 Change Log
- Enh #7918: `yii\widgets\Pjax` got ability to avoid registering link/form handler via setting `false` to `$linkSelector`/`$formSelector` (usualdesigner, Alex-Code, samdark)
- Enh #7973: Added `Schema::getSchemaNames` method (nineinchnick)
- Enh #8027: Added support for using sub queries in simple Query WHERE conditions (cebe)
+- Enh #8064: Added ability to remove containing menu tag by setting `yii\widgets\Menu::$options['tag']` to `false` (kirsenn, samdark)
- Enh: Added `yii\helper\Console::wrapText()` method to wrap indented text by console window width and used it in `yii help` command (cebe)
- Enh: Implement batchInsert for oci (nineinchnick)
- Enh: Detecting IntegrityException for oci (nineinchnick)
diff --git a/framework/widgets/Menu.php b/framework/widgets/Menu.php
index 381fc86fd7..98adf01656 100644
--- a/framework/widgets/Menu.php
+++ b/framework/widgets/Menu.php
@@ -79,7 +79,7 @@ class Menu extends Widget
* specifies its `options`, it will be merged with this property before being used to generate the HTML
* attributes for the menu item tag. The following special options are recognized:
*
- * - tag: string, defaults to "li", the tag name of the item container tags.
+ * - tag: string, defaults to "li", the tag name of the item container tags. Set to false to disable container tag.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
@@ -175,7 +175,12 @@ class Menu extends Widget
if (!empty($items)) {
$options = $this->options;
$tag = ArrayHelper::remove($options, 'tag', 'ul');
- echo Html::tag($tag, $this->renderItems($items), $options);
+
+ if ($tag !== false) {
+ echo Html::tag($tag, $this->renderItems($items), $options);
+ } else {
+ echo $this->renderItems($items);
+ }
}
}
diff --git a/tests/unit/framework/widgets/MenuTest.php b/tests/unit/framework/widgets/MenuTest.php
index c953bbd3ba..2b578989a4 100644
--- a/tests/unit/framework/widgets/MenuTest.php
+++ b/tests/unit/framework/widgets/MenuTest.php
@@ -66,4 +66,39 @@ HTML
, $output);
}
+
+ /**
+ * @see https://github.com/yiisoft/yii2/issues/8064
+ */
+ public function testTagOption()
+ {
+ $output = Menu::widget([
+ 'route' => 'test/test',
+ 'params' => [],
+ 'encodeLabels' => true,
+ 'options' => [
+ 'tag' => false,
+ ],
+ 'items' => [
+ [
+ 'label' => 'item1',
+ 'url' => '#',
+ 'options' => ['tag' => 'div'],
+ ],
+ [
+ 'label' => 'item2',
+ 'url' => '#',
+ 'options' => ['tag' => false],
+ ],
+ ]
+ ]);
+
+ $this->assertEqualsWithoutLE(<<item1
+item2
+HTML
+ , $output);
+ }
+
+
}