# Widget Helper stripping attributes?

**URL:** https://meta.discourse.org/t/widget-helper-stripping-attributes/68014
**Category:** Development
**Created:** [August 14, 2017, 2:06pm UTC](https://meta.discourse.org/t/widget-helper-stripping-attributes/68014 "2017-08-14T14:06:56Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Bas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bas/32/294929_2.png) [@Bas](https://meta.discourse.org/u/Bas)
#### Post date: [August 14, 2017, 2:06pm UTC](https://meta.discourse.org/t/widget-helper-stripping-attributes/68014/1 "2017-08-14T14:06:57Z")

</div>

I was trying my hand at my first plugin, and to a certain extent [it worked quite OK](https://github.com/VonLion/discourse-menu-icon) 🙂

However, I’m having trouble with the helper class. The class seems to strip out certain attributes and I have no idea what’s happening.

I’m adding an `\<a>` with some classes and a few attributes.

I’m trying to add

- id
- href
- title
- aria-label
- \_target

The first three work fine, the last two don’t.

I’ve tried to reorder and rename the attributes. But it seems there is some sort of selection happening?

Snippet:

```javascript
decorateWidget('header-icons:before', helper => {
    return h('li.header-dropdown-toggle', [
        h('a.icon.btn-flat', {
                'id': 'my id',
                'href': 'http://example.com',
                'title': 'my title',
                'aria-label': 'my label',
                '_target': "_blank"
            }, [
                h('i.fa.fa-info.d-icon', {
                    'aria-hidden': 'true'
                })
            ]
        ),
    ]);
});

```

Rendered as

 ![45](https://global.discourse-cdn.com/meta/original/3X/3/f/3fa0e6133d4e14fc7d521b1ff6a59550f046ffc8.png)

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [August 14, 2017, 2:17pm UTC](https://meta.discourse.org/t/widget-helper-stripping-attributes/68014/2 "2017-08-14T14:17:36Z")

</div>

[https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/widgets/header.js.es6#L93-L104](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/widgets/header.js.es6#L93-L104)

As per above code, I guess it should be like below

```js
decorateWidget('header-icons:before', helper => {
    return h('li.header-dropdown-toggle', [
        h('a.icon.btn-flat', {
                'id': 'my id',
                'href': 'http://example.com',
                'title': 'my title',
                'attributes': {
                    'aria-label': 'my label',
                    'target': "_blank"
                }
            }, [
                h('i.fa.fa-info.d-icon', { 'attributes': {
                    'aria-hidden': 'true'
                }})
            ]
        ),
    ]);
});

```

Also `target` is not `_target`.

---

<div class="post-metadata">

### Author: ![Bas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bas/32/294929_2.png) [@Bas](https://meta.discourse.org/u/Bas)
#### Post date: [August 14, 2017, 2:27pm UTC](https://meta.discourse.org/t/widget-helper-stripping-attributes/68014/3 "2017-08-14T14:27:13Z")

</div>

Works like a charm, thanks! 🙂

---

<div class="post-metadata">

### Author: ![gormus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gormus/32/428592_2.png) [@gormus](https://meta.discourse.org/u/gormus)
#### Post date: [May 15, 2023, 11:26pm UTC](https://meta.discourse.org/t/widget-helper-stripping-attributes/68014/4 "2023-05-15T23:26:09Z")

</div>

With the help of this topic, I was able to create an SVG object using the `h` helper:

```js
    let logo = h("svg", {
        "attributes": {
          "width": "22",
          "height": "24",
          "viewBox": "0 0 22 24",
          "fill": "none",
          "xmlns": "http://www.w3.org/2000/svg"
        }
      },
      h("path", {
        "attributes": {
          "d": "M11.5992 4.29387L15.4141 ... 0V4.29387Z",
          "fill": "#000000"
        }
      })
    );

```

However, I see that the `viewBox`(\*) attribute is always rendered in all lower-case.

The SVG image is generated with all defined attributes (\*), but it does not render on the page. What am I missing?

I realize this is provided by the [virtual-dom](https://github.com/Matt-Esch/virtual-dom) package, but I couldn’t find the solution there.

---

<div class="post-metadata">

### Author: ![Bas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bas/32/294929_2.png) [@Bas](https://meta.discourse.org/u/Bas)
#### Post date: [May 24, 2023, 8:03am UTC](https://meta.discourse.org/t/widget-helper-stripping-attributes/68014/5 "2023-05-24T08:03:40Z")

</div>

Interesting.. Could you link/paste the generated SVG too?

---

<div class="post-metadata">

### Author: ![gormus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gormus/32/428592_2.png) [@gormus](https://meta.discourse.org/u/gormus)
#### Post date: [May 24, 2023, 4:28pm UTC](https://meta.discourse.org/t/widget-helper-stripping-attributes/68014/7 "2023-05-24T16:28:45Z")

</div>

@Bas Unfortunately, I don’t have the same code anymore. I moved on, and implemented the logo via different methods.

But this I can tell you now; if I inspected the browser for the SVG image, and edited as HTML in the browser to rename `viewbox` attribute to `viewBox`, the SVG image would render correctly in the browser.

And it would be identical to the original SVG image which I deconstructed into `h` helper.

---

<div class="post-metadata">

### Author: ![Bas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bas/32/294929_2.png) [@Bas](https://meta.discourse.org/u/Bas)
#### Post date: [May 25, 2023, 7:40am UTC](https://meta.discourse.org/t/widget-helper-stripping-attributes/68014/8 "2023-05-25T07:40:58Z")

</div>

Ok, thank you for letting us know. Happy that you managed to sort it with a different method!

---

<div class="post-metadata">

### Author: ![Bas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bas/32/294929_2.png) [@Bas](https://meta.discourse.org/u/Bas)
#### Post date: [June 24, 2023, 7:41am UTC](https://meta.discourse.org/t/widget-helper-stripping-attributes/68014/9 "2023-06-24T07:41:12Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
