Skip to content

Commit 2912808

Browse files
authored
Merge pull request #189 from elguitarraverde/patch-1
fix: scripts attributes not working
2 parents 47d1848 + 5f3d526 commit 2912808

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/Html/Builder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ public static function useWebpack(): void
100100
* @param array $attributes
101101
* @return \Illuminate\Support\HtmlString
102102
*/
103-
public function scripts(string $script = null, array $attributes = ['type' => 'text/javascript']): HtmlString
103+
public function scripts(string $script = null, array $attributes = []): HtmlString
104104
{
105105
$script = $script ?: $this->generateScripts();
106106
$attributes = $this->html->attributes(
107-
array_merge($attributes, ['type' => static::$jsType])
107+
array_merge($attributes, ['type' => $attributes['type'] ?? static::$jsType])
108108
);
109109

110110
return new HtmlString("<script{$attributes}>$script</script>");

tests/BuilderTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,31 @@
1111

1212
class BuilderTest extends TestCase
1313
{
14+
/** @test */
15+
public function it_can_get_script_default_type_attribute()
16+
{
17+
$html = $this->getHtmlBuilder()->scripts()->toHtml();
18+
19+
$this->assertStringContainsString('type="text/javascript"', $html);
20+
}
21+
22+
/** @test */
23+
public function it_can_set_script_type_attribute()
24+
{
25+
$html = $this->getHtmlBuilder()->scripts(attributes: ['type' => 'module'])->toHtml();
26+
27+
$this->assertStringContainsString('type="module"', $html);
28+
}
29+
30+
/** @test */
31+
public function it_can_set_multiple_script_attributes()
32+
{
33+
$html = $this->getHtmlBuilder()->scripts(attributes: ['prop1' => 'val1', 'prop2' => 'val2'])->toHtml();
34+
35+
$this->assertStringContainsString('prop1="val1"', $html);
36+
$this->assertStringContainsString('prop2="val2"', $html);
37+
}
38+
1439
/** @test */
1540
public function it_can_use_vitejs_module_script()
1641
{

0 commit comments

Comments
 (0)