Skip to content

Commit a630d58

Browse files
Add id to docs (#144)
* add phpdoc to attributes class * add id into introduction * add id into `item-attributes` * add title for `class` and `id` in item-attributes * Fix styling * Update docs/introduction.md Co-authored-by: Sebastian De Deyne <sebastiandedeyne@gmail.com> * Change class to classes into `item-attributes` Co-authored-by: Sebastian De Deyne <sebastiandedeyne@gmail.com> * remove phpdoc in Attributes * Fix styling * Update docs/controlling-the-html-output/item-attributes.md Co-authored-by: Sebastian De Deyne <sebastiandedeyne@gmail.com> --------- Co-authored-by: milwad-dev <milwad-dev@users.noreply.github.com> Co-authored-by: Sebastian De Deyne <sebastiandedeyne@gmail.com>
1 parent fbe3c11 commit a630d58

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

docs/controlling-the-html-output/item-attributes.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ weight: 1
55

66
The `Menu` and `Link` classes use the `HtmlAttributes` trait, which enables you to add attributes to their main elements (respectively the `ul` and `a` tags).
77

8+
## Adding classes to a menu
9+
810
The trait provides two methods to set attributes: `setAttribute` and `addClass`.
911

1012
```php
@@ -30,3 +32,18 @@ Link::to('#', 'Back to top')
3032
```
3133

3234
If you want to add classes or set attributes to all items in a menu, the `Menu` class provides some convenience methods: `addItemClass`, `setItemAttribute`.
35+
36+
## Adding an ID to a menu
37+
38+
The trait provides two methods to set attributes: `setAttribute` and `id`.
39+
40+
```php
41+
Menu::new()
42+
->setAttribute('role', 'navigation')
43+
->id('nav');
44+
```
45+
46+
```html
47+
<ul role="navigation" id="nav"></ul>
48+
```
49+

docs/introduction.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ Menu::new()
5454
</div
5555
```
5656

57+
## Adding an ID to elements
58+
59+
You can add id, so you can easily target some of these elements with CSS or JS.
60+
61+
```php
62+
Menu::new()
63+
->id('navigation')
64+
->add(Link::to('/', 'Home')->id('home-link'))
65+
->add(Link::to('/about', 'About'))
66+
->add(Link::to('/contact', 'Contact'))
67+
```
68+
69+
```html
70+
<ul id="navigation">
71+
<li><a href="/" id="home-link">Home</a></li>
72+
<li><a href="/about">About</a></li>
73+
<li><a href="/contact">Contact</a></li>
74+
</ul>
75+
```
76+
5777
## Not Afraid of Depths
5878

5979
The menu supports submenus, which in turn can be nested infinitely.

0 commit comments

Comments
 (0)