Explorar el Código

HasHtmlAttributes

jqh hace 6 años
padre
commit
3e6b115785

+ 3 - 3
src/Grid/Row.php

@@ -53,7 +53,7 @@ class Row
      */
     public function getRowAttributes()
     {
-        return $this->formatHtmlAttribute($this->attributes);
+        return $this->formatHtmlAttributes($this->attributes);
     }
 
     /**
@@ -69,7 +69,7 @@ class Row
             ($column = $this->grid->getColumns()->get($column))
             && ($attributes = $column->getAttributes())
         ) {
-            return $this->formatHtmlAttribute($attributes);
+            return $this->formatHtmlAttributes($attributes);
         }
         return '';
     }
@@ -81,7 +81,7 @@ class Row
      *
      * @return string
      */
-    private function formatHtmlAttribute($attributes = [])
+    private function formatHtmlAttributes($attributes = [])
     {
         $attrArr = [];
         foreach ($attributes as $name => $val) {

+ 1 - 1
src/Grid/RowAction.php

@@ -98,7 +98,7 @@ abstract class RowAction extends GridAction
             $href = 'javascript:void(0);';
         }
 
-        $attributes = $this->formatHtmlAttribute();
+        $attributes = $this->formatHtmlAttributes();
 
         return sprintf(
             "<a data-_key='%s' href='%s' class='%s' {$attributes}>%s</a>",

+ 50 - 3
src/Traits/HasHtmlAttributes.php

@@ -3,6 +3,7 @@
 namespace Dcat\Admin\Traits;
 
 use Dcat\Admin\Support\Helper;
+use Illuminate\Support\Arr;
 
 trait HasHtmlAttributes
 {
@@ -29,8 +30,43 @@ trait HasHtmlAttributes
     }
 
     /**
-     * @param $key
-     * @param null $default
+     * @param string|array $keys
+     * @return $this
+     */
+    public function forgetHtmlAttribute($keys)
+    {
+        Arr::forget($this->htmlAttributes, $keys);
+
+        return $this;
+    }
+
+    /**
+     * @return array
+     */
+    public function getHtmlAttributes()
+    {
+        return $this->htmlAttributes;
+    }
+
+    /**
+     * Set default attribute.
+     *
+     * @param string $attribute
+     * @param mixed $value
+     * @return $this
+     */
+    public function defaultHtmlAttribute($attribute, $value)
+    {
+        if (!array_key_exists($attribute, $this->htmlAttributes)) {
+            $this->setHtmlAttribute($attribute, $value);
+        }
+
+        return $this;
+    }
+
+    /**
+     * @param mixed $key
+     * @param mixed $default
      * @return |null
      */
     public function getHtmlAttribute($key, $default = null)
@@ -39,9 +75,20 @@ trait HasHtmlAttributes
     }
 
     /**
+     * @param mixed $key
+     * @return |null
+     */
+    public function hasHtmlAttribute($key)
+    {
+        return array_key_exists($key, $this->htmlAttributes);
+    }
+
+    /**
+     * Build an HTML attribute string from an array.
+     *
      * @return string
      */
-    public function formatHtmlAttribute()
+    public function formatHtmlAttributes()
     {
         return Helper::buildHtmlAttributes($this->htmlAttributes);
     }

+ 2 - 2
src/Widgets/Accordion.php

@@ -66,10 +66,10 @@ class Accordion extends Widget implements Renderable
     public function variables()
     {
         return [
-            'id'         => $this->attributes['id'],
+            'id'         => $this->getHtmlAttribute('id'),
             'items'      => $this->items,
             'panelStyle' => $this->panelStyle,
-            'attributes' => $this->formatAttributes(),
+            'attributes' => $this->formatHtmlAttributes(),
         ];
     }
 }

+ 1 - 1
src/Widgets/Alert.php

@@ -127,7 +127,7 @@ class Alert extends Widget implements Renderable
             'title'        => $this->title,
             'content'      => $this->content,
             'icon'         => $this->icon,
-            'attributes'   => $this->formatAttributes(),
+            'attributes'   => $this->formatHtmlAttributes(),
             'showCloseBtn' => $this->showCloseBtn,
         ];
     }

+ 1 - 1
src/Widgets/Box.php

@@ -170,7 +170,7 @@ class Box extends Widget implements Renderable
             'title'      => $this->title,
             'content'    => $this->content,
             'tools'      => $this->tools,
-            'attributes' => $this->formatAttributes(),
+            'attributes' => $this->formatHtmlAttributes(),
             'padding'    => $this->padding,
         ];
     }

+ 1 - 1
src/Widgets/Card.php

@@ -96,7 +96,7 @@ class Card extends Widget
             'title'      => $this->title,
             'content'    => $this->content,
             'tools'      => $this->tools,
-            'attributes' => $this->formatAttributes(),
+            'attributes' => $this->formatHtmlAttributes(),
             'style'      => $this->style,
             'padding'    => $this->padding,
         ];

+ 3 - 5
src/Widgets/Carousel.php

@@ -2,9 +2,7 @@
 
 namespace Dcat\Admin\Widgets;
 
-use Illuminate\Contracts\Support\Renderable;
-
-class Carousel extends Widget implements Renderable
+class Carousel extends Widget
 {
     /**
      * @var string
@@ -32,7 +30,7 @@ class Carousel extends Widget implements Renderable
 
         $this->id('carousel-'.uniqid());
         $this->class('carousel slide');
-        $this->offsetSet('data-ride', 'carousel');
+        $this->setHtmlAttribute('data-ride', 'carousel');
     }
 
     /**
@@ -55,7 +53,7 @@ class Carousel extends Widget implements Renderable
         $variables = [
             'items'      => $this->items,
             'title'      => $this->title,
-            'attributes' => $this->formatAttributes(),
+            'attributes' => $this->formatHtmlAttributes(),
             'id'         => $this->id,
         ];
 

+ 2 - 2
src/Widgets/Chart/Chart.php

@@ -396,7 +396,7 @@ JS
 
         $this->script = $this->script();
 
-        $this->setAttribute([
+        $this->setHtmlAttribute([
             'id' => $this->id,
         ]);
 
@@ -404,7 +404,7 @@ JS
 
         return <<<HTML
 <div class="chart" style="{$this->containerStyle}">
-    <canvas {$this->formatAttributes()}>
+    <canvas {$this->formatHtmlAttributes()}>
         Your browser does not support the canvas element.
     </canvas>
 </div>

+ 2 - 2
src/Widgets/Code.php

@@ -91,7 +91,7 @@ class Code extends Markdown
     public function read($file, $start = 1, $end = 10)
     {
         if (!$file or !is_readable($file) || $end < $start) {
-            return [];
+            return $this;
         }
 
         $file = fopen($file, 'r');
@@ -119,7 +119,7 @@ class Code extends Markdown
         }
 
         return <<<EOF
-<div {$this->formatAttributes()}><textarea style="display:none;">
+<div {$this->formatHtmlAttributes()}><textarea style="display:none;">
 ```{$this->lang}
 {$this->content}
 ```

+ 1 - 1
src/Widgets/DataCard/Card.php

@@ -126,7 +126,7 @@ class Card extends Widget
 
     protected function setupFetchScript()
     {
-        $id = $this->attributes['id'];
+        $id = $this->getHtmlAttribute('id');
 
         $this->fetching(
             <<<SCRIPT

+ 6 - 3
src/Widgets/DataCard/DoughnutChartCard.php

@@ -36,8 +36,8 @@ class DoughnutChartCard extends Card
             ->responsive(false) // 去掉自适应,这里固定大小即可,否则手机端显示会有问题
             ->height('85px')
             ->width('85px')
-            ->setAttribute('width', '85px')
-            ->setAttribute('height', '85px')
+            ->setHtmlAttribute('width', '85px')
+            ->setHtmlAttribute('height', '85px')
             ->disableLegend();
     }
 
@@ -155,6 +155,9 @@ HTML;
     {
         $this->buildDots();
 
-        return $this->chart->toJsonResponse(true, array_merge($this->buildJsonResponseArray(), $data));
+        return $this->chart->toJsonResponse(
+            true,
+            array_merge($this->buildJsonResponseArray(), $data)
+        );
     }
 }

+ 4 - 1
src/Widgets/DataCard/LineChartCard.php

@@ -59,6 +59,9 @@ class LineChartCard extends Card
      */
     public function toJsonResponse(array $data = [])
     {
-        return $this->chart->toJsonResponse(true, array_merge($this->buildJsonResponseArray(), $data));
+        return $this->chart->toJsonResponse(
+            true,
+            array_merge($this->buildJsonResponseArray(), $data)
+        );
     }
 }

+ 2 - 2
src/Widgets/DataCard/PieChartCard.php

@@ -13,8 +13,8 @@ class PieChartCard extends DoughnutChartCard
                 ->responsive(false)
                 ->height('85px')
                 ->width('85px')
-                ->setAttribute('width', '85px')
-                ->setAttribute('height', '85px')
+                ->setHtmlAttribute('width', '85px')
+                ->setHtmlAttribute('height', '85px')
                 ->disableLegend();
     }
 }

+ 2 - 2
src/Widgets/DataCard/PolarAreaChartCard.php

@@ -13,8 +13,8 @@ class PolarAreaChartCard extends DoughnutChartCard
                 ->responsive(false)
                 ->height('85px')
                 ->width('85px')
-                ->setAttribute('width', '85px')
-                ->setAttribute('height', '85px')
+                ->setHtmlAttribute('width', '85px')
+                ->setHtmlAttribute('height', '85px')
                 ->disableLegend();
     }
 }

+ 2 - 2
src/Widgets/Dump.php

@@ -64,10 +64,10 @@ class Dump extends Widget
 
     public function render()
     {
-        $this->defaultAttribute('style', 'white-space:pre-wrap');
+        $this->defaultHtmlAttribute('style', 'white-space:pre-wrap');
 
         return <<<EOF
-<div style="padding:{$this->padding}"><pre class="dump" {$this->formatAttributes()}>{$this->content}</pre></div>
+<div style="padding:{$this->padding}"><pre class="dump" {$this->formatHtmlAttributes()}>{$this->content}</pre></div>
 EOF;
 
     }

+ 11 - 58
src/Widgets/Form.php

@@ -5,6 +5,7 @@ namespace Dcat\Admin\Widgets;
 use Closure;
 use Dcat\Admin\Admin;
 use Dcat\Admin\Form\Field;
+use Dcat\Admin\Traits\HasHtmlAttributes;
 use Illuminate\Contracts\Support\Arrayable;
 use Illuminate\Contracts\Support\Renderable;
 use Illuminate\Support\Arr;
@@ -70,6 +71,8 @@ use Illuminate\Support\Str;
  */
 class Form implements Renderable
 {
+    use HasHtmlAttributes;
+
     /**
      * @var Field[]
      */
@@ -85,11 +88,6 @@ class Form implements Renderable
      */
     protected $data = [];
 
-    /**
-     * @var array
-     */
-    protected $attributes = [];
-
     /**
      * Available buttons.
      *
@@ -138,13 +136,13 @@ class Form implements Renderable
      */
     protected function initFormAttributes()
     {
-        $this->attributes = [
+        $this->setHtmlAttribute([
             'method'         => 'POST',
             'action'         => '',
             'class'          => 'form-horizontal',
             'accept-charset' => 'UTF-8',
             'pjax-container' => true,
-        ];
+        ]);
     }
 
     /**
@@ -156,7 +154,7 @@ class Form implements Renderable
      */
     public function action($action)
     {
-        return $this->attribute('action', $action);
+        return $this->setHtmlAttribute('action', $action);
     }
 
     /**
@@ -164,7 +162,7 @@ class Form implements Renderable
      */
     public function getAction()
     {
-        return $this->attributes['action'];
+        return $this->getHtmlAttribute('action');
     }
 
     /**
@@ -176,7 +174,7 @@ class Form implements Renderable
      */
     public function method($method = 'POST')
     {
-        return $this->attribute('method', strtoupper($method));
+        return $this->setHtmlAttribute('method', strtoupper($method));
     }
 
     /**
@@ -200,28 +198,6 @@ class Form implements Renderable
         return $fieldset;
     }
 
-
-    /**
-     * Add form attributes.
-     *
-     * @param string|array $attr
-     * @param string       $value
-     *
-     * @return $this
-     */
-    public function attribute($attr, $value = '')
-    {
-        if (is_array($attr)) {
-            foreach ($attr as $key => $value) {
-                $this->attribute($key, $value);
-            }
-        } else {
-            $this->attributes[$attr] = $value;
-        }
-
-        return $this;
-    }
-
     /**
      * Disable Pjax.
      *
@@ -229,7 +205,7 @@ class Form implements Renderable
      */
     public function disablePjax()
     {
-        Arr::forget($this->attributes, 'pjax-container');
+        $this->forgetHtmlAttribute('pjax-container');
 
         return $this;
     }
@@ -342,35 +318,12 @@ class Form implements Renderable
 
         return [
             'fields'     => $this->fields,
-            'attributes' => $this->formatAttribute(),
-            'method'     => $this->attributes['method'],
+            'attributes' => $this->formatHtmlAttributes(),
+            'method'     => $this->getHtmlAttribute('method'),
             'buttons'    => $this->buttons,
         ];
     }
 
-    /**
-     * Format form attributes form array to html.
-     *
-     * @param array $attributes
-     *
-     * @return string
-     */
-    public function formatAttribute($attributes = [])
-    {
-        $attributes = $attributes ?: $this->attributes;
-
-        if ($this->hasFile()) {
-            $attributes['enctype'] = 'multipart/form-data';
-        }
-
-        $html = [];
-        foreach ($attributes as $key => $val) {
-            $html[] = "$key=\"$val\"";
-        }
-
-        return implode(' ', $html) ?: '';
-    }
-
     /**
      * Determine if form fields has files.
      *

+ 2 - 2
src/Widgets/Markdown.php

@@ -77,7 +77,7 @@ class Markdown extends Widget
         }
 
         return <<<EOF
-<div {$this->formatAttributes()}><textarea style="display:none;">{$this->content}</textarea></div>
+<div {$this->formatHtmlAttributes()}><textarea style="display:none;">{$this->content}</textarea></div>
 EOF;
 
     }
@@ -86,7 +86,7 @@ EOF;
     {
         $id = uniqid();
 
-        $this->defaultAttribute('id', $id);
+        $this->defaultHtmlAttribute('id', $id);
 
         $opts = json_encode($this->options);
 

+ 1 - 1
src/Widgets/NavList.php

@@ -85,6 +85,6 @@ JS
             $html .= "<li class='$active bg-white'>$item</li>";
         }
 
-        return "<ul {$this->formatAttributes()}>{$html}</ul>";
+        return "<ul {$this->formatHtmlAttributes()}>{$html}</ul>";
     }
 }

+ 9 - 7
src/Widgets/Navbar.php

@@ -8,6 +8,8 @@ use Illuminate\Support\Str;
 
 class Navbar extends Widget
 {
+    const DROPDOWN_FLAG_KEY = '__dropdown__';
+
     protected $view = 'admin::widgets.navbar';
 
     protected $id;
@@ -104,7 +106,7 @@ class Navbar extends Widget
             $closure($dropdown);
         }
 
-        $this->items['__dropdown__'] = $dropdown;
+        $this->items[self::DROPDOWN_FLAG_KEY] = $dropdown;
 
         return $this;
     }
@@ -112,7 +114,7 @@ class Navbar extends Widget
     public function variables()
     {
         foreach ($this->items as $k => &$item) {
-            if ($k === '__dropdown__') {
+            if ($k === self::DROPDOWN_FLAG_KEY) {
                 continue;
             }
 
@@ -143,11 +145,11 @@ JS
         }
 
         return [
-            'id' => $this->id,
-            'title' => $this->title,
-            'items' => $this->items,
-            'attributes' => $this->formatAttributes(),
-            'actives' => $this->actives,
+            'id'         => $this->id,
+            'title'      => $this->title,
+            'items'      => $this->items,
+            'attributes' => $this->formatHtmlAttributes(),
+            'actives'    => $this->actives,
         ];
     }
 

+ 4 - 4
src/Widgets/Radio.php

@@ -38,12 +38,12 @@ class Radio extends Widget
             return $this;
         }
 
-        return $this->setAttribute('disabled', 'disabled');
+        return $this->setHtmlAttribute('disabled', 'disabled');
     }
 
     public function name($name)
     {
-        return $this->setAttribute('name', $name);
+        return $this->setHtmlAttribute('name', $name);
     }
 
     public function inline()
@@ -104,7 +104,7 @@ class Radio extends Widget
         return [
             'style'      => $this->style,
             'options'    => $this->options,
-            'attributes' => $this->formatAttributes(),
+            'attributes' => $this->formatHtmlAttributes(),
             'checked'    => $this->checked,
             'inline'     => $this->inline ? $this->type.'-inline' : '',
             'disabled'   => $this->disabledValues,
@@ -113,7 +113,7 @@ class Radio extends Widget
 
     public function render()
     {
-        $this->setAttribute('type', $this->type);
+        $this->setHtmlAttribute('type', $this->type);
 
         return parent::render();
     }

+ 2 - 2
src/Widgets/Sparkline/Sparkline.php

@@ -171,13 +171,13 @@ JS
 
         Admin::script($this->script());
 
-        $this->setAttribute([
+        $this->setHtmlAttribute([
             'id' => $this->id,
         ]);
 
         $this->collectAssets();
         return <<<HTML
-<span {$this->formatAttributes()}></span>
+<span {$this->formatHtmlAttributes()}></span>
 HTML;
 
     }

+ 1 - 1
src/Widgets/Tab.php

@@ -167,7 +167,7 @@ class Tab extends Widget implements Renderable
     {
         $data = array_merge(
             $this->data,
-            ['attributes' => $this->formatAttributes(), 'padding' => $this->padding]
+            ['attributes' => $this->formatHtmlAttributes(), 'padding' => $this->padding]
         );
 
         return view($this->view, $data)->render();

+ 31 - 27
src/Widgets/Table.php

@@ -30,7 +30,7 @@ class Table extends Widget implements Renderable
     /**
      * @var int
      */
-    protected $level = 0;
+    protected $depth = 0;
 
     /**
      * Table constructor.
@@ -62,9 +62,13 @@ class Table extends Widget implements Renderable
         return $this;
     }
 
-    public function level($level)
+    /**
+     * @param int $depth
+     * @return $this
+     */
+    public function depth(int $depth)
     {
-        $this->level = $level;
+        $this->depth = $depth;
 
         return $this;
     }
@@ -78,37 +82,37 @@ class Table extends Widget implements Renderable
      */
     public function setRows($rows = [])
     {
+        if (! Arr::isAssoc($rows)) {
+            $this->rows = $rows;
+
+            return $this;
+        }
+
         $noTrPadding = false;
 
-        if (Arr::isAssoc($rows)) {
-            foreach ($rows as $key => $item) {
-                if (is_array($item)) {
-                    if (Arr::isAssoc($item)) {
-                        $borderLeft = $this->level ? 'table-left-border-nofirst' : 'table-left-border';
-
-                        $item = static::make()
-                            ->level($this->level + 1)
-                            ->setRows($item)
-                            ->class('table-no-top-border '.$borderLeft, true)
-                            ->render();
-
-                        if (!$noTrPadding) {
-                            $this->class('table-no-tr-padding', true);
-                        }
-                        $noTrPadding = true;
-                    } else {
-                        $item = json_encode($item, JSON_UNESCAPED_UNICODE);
+        foreach ($rows as $key => $item) {
+            if (is_array($item)) {
+                if (Arr::isAssoc($item)) {
+                    $borderLeft = $this->level ? 'table-left-border-nofirst' : 'table-left-border';
+
+                    $item = static::make()
+                        ->depth($this->depth + 1)
+                        ->setRows($item)
+                        ->class('table-no-top-border '.$borderLeft, true)
+                        ->render();
+
+                    if (!$noTrPadding) {
+                        $this->class('table-no-tr-padding', true);
                     }
+                    $noTrPadding = true;
+                } else {
+                    $item = json_encode($item, JSON_UNESCAPED_UNICODE);
                 }
-
-                $this->rows[] = [$key, $item];
             }
 
-            return $this;
+            $this->rows[] = [$key, $item];
         }
 
-        $this->rows = $rows;
-
         return $this;
     }
 
@@ -137,7 +141,7 @@ class Table extends Widget implements Renderable
             'headers'    => $this->headers,
             'rows'       => $this->rows,
             'style'      => $this->style,
-            'attributes' => $this->formatAttributes(),
+            'attributes' => $this->formatHtmlAttributes(),
         ];
 
         return view($this->view, $vars)->render();

+ 1 - 1
src/Widgets/Terminal.php

@@ -51,7 +51,7 @@ class Terminal extends Widget
         static::$style = null;
 
         return <<<EOF
-{$style}<pre {$this->formatAttributes()}>{$this->content}</pre>
+{$style}<pre {$this->formatHtmlAttributes()}>{$this->content}</pre>
 EOF;
 
     }

+ 2 - 2
src/Widgets/Tooltip.php

@@ -158,10 +158,10 @@ class Tooltip extends Widget
             Admin::style(".tooltip-inner{max-width:{$this->maxWidth}}");
         }
 
-        $this->defaultAttribute('class', 'tooltip-inner');
+        $this->defaultHtmlAttribute('class', 'tooltip-inner');
         $this->style('background:'.$this->bg, true);
 
-        $this->options['template'] = "<div class='tooltip' role='tooltip'><div class='tooltip-arrow' style='border-{$this->options['placement']}-color:{$this->bg}'></div><div {$this->formatAttributes()}></div></div>";
+        $this->options['template'] = "<div class='tooltip' role='tooltip'><div class='tooltip-arrow' style='border-{$this->options['placement']}-color:{$this->bg}'></div><div {$this->formatHtmlAttributes()}></div></div>";
 
         $opts = json_encode($this->options, JSON_UNESCAPED_UNICODE);
 

+ 1 - 1
src/Widgets/Tree.php

@@ -110,7 +110,7 @@ class Tree extends Widget
 
         $this->id($id);
         $this->class('jstree-wrapper');
-        $this->defaultAttribute('style', 'border:0;padding:5px 0');
+        $this->defaultHtmlAttribute('style', 'border:0;padding:5px 0');
 
         $this->formatNodes();
 

+ 9 - 65
src/Widgets/Widget.php

@@ -4,6 +4,7 @@ namespace Dcat\Admin\Widgets;
 
 use Dcat\Admin\Admin;
 use Dcat\Admin\Support\Helper;
+use Dcat\Admin\Traits\HasHtmlAttributes;
 use Illuminate\Contracts\Support\Arrayable;
 use Illuminate\Contracts\Support\Htmlable;
 use Illuminate\Contracts\Support\Renderable;
@@ -15,6 +16,8 @@ use Illuminate\Contracts\Support\Renderable;
  */
 abstract class Widget implements Renderable
 {
+    use HasHtmlAttributes;
+
     /**
      * @var array
      */
@@ -35,11 +38,6 @@ abstract class Widget implements Renderable
      */
     protected $script = '';
 
-    /**
-     * @var array
-     */
-    protected $attributes = [];
-
     /**
      * @var array
      */
@@ -82,16 +80,6 @@ abstract class Widget implements Renderable
         return $this->options;
     }
 
-    /**
-     * Get the attributes from the fluent instance.
-     *
-     * @return array
-     */
-    public function getAttributes()
-    {
-        return $this->attributes;
-    }
-
     /**
      * Variables in view.
      *
@@ -100,7 +88,7 @@ abstract class Widget implements Renderable
     public function variables()
     {
         return array_merge($this->variables, [
-            'attributes' => $this->formatAttributes(),
+            'attributes' => $this->formatHtmlAttributes(),
             'options'    => $this->options,
         ]);
     }
@@ -154,50 +142,6 @@ abstract class Widget implements Renderable
         return $this->script;
     }
 
-    /**
-     * Set default attribute.
-     *
-     * @param string $attribute
-     * @param mixed $value
-     * @return $this
-     */
-    public function defaultAttribute($attribute, $value)
-    {
-        if (!array_key_exists($attribute, $this->attributes)) {
-            $this->setAttribute($attribute, $value);
-        }
-
-        return $this;
-    }
-
-    /**
-     * Set element attributes.
-     *
-     * @param $k
-     * @param null $v
-     * @return $this
-     */
-    public function setAttribute($k, $v = null)
-    {
-        if (is_array($k)) {
-            $this->attributes = array_merge($this->attributes, $k);
-        } else {
-            $this->attributes[$k] = $v;
-        }
-
-        return $this;
-    }
-
-    /**
-     * Build an HTML attribute string from an array.
-     *
-     * @return string
-     */
-    public function formatAttributes()
-    {
-        return Helper::buildHtmlAttributes($this->getAttributes());
-    }
-
     /**
      * @param $method
      * @param $parameters
@@ -210,17 +154,17 @@ abstract class Widget implements Renderable
             $append = $parameters[1] ?? ($method === 'class' ? false : true);
 
             if ($append) {
-                $original = $this->attributes[$method] ?? '';
+                $original = $this->htmlAttributes[$method] ?? '';
 
                 $de = $method === 'style' ? ';' : ' ';
 
                 $value = $original . $de . $value;
             }
 
-            return $this->setAttribute($method, $value);
+            return $this->setHtmlAttribute($method, $value);
         }
 
-        $this->attributes[$method] = count($parameters) > 0 ? $parameters[0] : true;
+        $this->htmlAttributes[$method] = count($parameters) > 0 ? $parameters[0] : true;
 
         return $this;
     }
@@ -231,7 +175,7 @@ abstract class Widget implements Renderable
      */
     public function __get($key)
     {
-        return $this->attributes[$key] ?? null;
+        return $this->htmlAttributes[$key] ?? null;
     }
 
     /**
@@ -241,7 +185,7 @@ abstract class Widget implements Renderable
      */
     public function __set($key, $value)
     {
-        $this->attributes[$key] = $value;
+        $this->htmlAttributes[$key] = $value;
     }
 
     /**