Compare commits
3 Commits
issue/8-th
...
issue/10-i
| Author | SHA1 | Date | |
|---|---|---|---|
| ade021b8a6 | |||
| 5b13a21a82 | |||
| 1b917b4cac |
@@ -2,6 +2,8 @@
|
||||
|
||||
## [X.X.X] - XXXX-XX-XX
|
||||
- Allow passing in a space-separated string to the `classes` option
|
||||
- Add new exceptions and messages to make debugging a little bit faster
|
||||
- Set `aria-hidden` attribute depending on whether a `title` has been set
|
||||
|
||||
## [1.0.0] - 2023-06-27
|
||||
- First major version release
|
||||
|
||||
@@ -62,8 +62,11 @@ final class IconRuntime implements RuntimeExtensionInterface
|
||||
$classes = trim($colourClasses.' '.$extraClasses);
|
||||
$this->addClassesToSvg($svg, $classes);
|
||||
|
||||
$svg = $this->addAttribute($svg, 'aria-hidden', 'true');
|
||||
|
||||
if (null !== $options['title']) {
|
||||
$this->addTitleToSvg($svg, $options['title']);
|
||||
$svg = $this->addAttribute($svg, 'aria-hidden', 'false');
|
||||
}
|
||||
|
||||
$this->setSvgHeightAndWidth($svg, $options['size']);
|
||||
@@ -217,6 +220,14 @@ final class IconRuntime implements RuntimeExtensionInterface
|
||||
$svg = $this->removeXMLDeclaration($svgAsXml->saveXML());
|
||||
}
|
||||
|
||||
private function addAttribute(string $svg, string $attribute, string $value): string
|
||||
{
|
||||
$xml = new \SimpleXMLElement($svg);
|
||||
$xml = $this->addAttributeToXmlElement($xml, $attribute, $value);
|
||||
|
||||
return $this->removeXMLDeclaration($xml->saveXML());
|
||||
}
|
||||
|
||||
private function isValidXml(string $input): bool
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -280,4 +280,23 @@ class IconRuntimeTest extends TestCase
|
||||
$this->assertStringNotContainsString($needleA, $contents);
|
||||
$this->assertStringNotContainsString($needleB, $contents);
|
||||
}
|
||||
|
||||
public function testAriaHiddenAttributeIsAdded(): void
|
||||
{
|
||||
$contents = $this->icon->renderIcon(['icon' => self::ICON]);
|
||||
$this->assertMatchesRegularExpression('/<svg.+aria-hidden="true".*>/', $contents);
|
||||
}
|
||||
|
||||
public function testAriaHiddenAttributeIsSetToTrueIfAlreadyPresent(): void
|
||||
{
|
||||
$contents = $this->icon->renderIcon(['icon' => 'attr']);
|
||||
$this->assertMatchesRegularExpression('/<svg.+aria-hidden="true".*>/', $contents);
|
||||
$this->assertDoesNotMatchRegularExpression('/<svg.+aria-hidden="false".*>/', $contents);
|
||||
}
|
||||
|
||||
public function testAriaHiddenAttributeIsSetToFalseIfATitleIsPassedIn(): void
|
||||
{
|
||||
$contents = $this->icon->renderIcon(['icon' => self::ICON, 'title' => 'something']);
|
||||
$this->assertMatchesRegularExpression('/<svg.+aria-hidden="false".*>/', $contents);
|
||||
}
|
||||
}
|
||||
|
||||
10
tests/icons/attr.svg
Normal file
10
tests/icons/attr.svg
Normal file
@@ -0,0 +1,10 @@
|
||||
<svg aria-hidden="false" xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="96 96 320 320">
|
||||
<title>Some cross lol</title>
|
||||
<line fill="rgb(0, 0, 0)"></line>
|
||||
<line fill="#000"></line>
|
||||
<line fill="#000000"></line>
|
||||
<line stroke="currentColor" fill="black"></line>
|
||||
<line x1="256" y1="112" x2="256" y2="400" width="101" height="101" style="fill: none; stroke: rgb(0,0, 0); stroke-linecap: round; stroke-linejoin: round; stroke-width: 32px;"></line>
|
||||
<line x1="400" y1="256" x2="112" y2="256" width="102" height="102" style="fill: none; stroke: #000; stroke-linecap: round; stroke-linejoin: round; stroke-width: 32px;"></line>
|
||||
<polyline points="112 244 256 100 400 244" style="fill:#000;fill:#000000;fill: black;fill:rgb(0,0,0);stroke:#000;stroke:#000000;stroke:black;stroke:rgb(0, 0, 0);stroke-linecap:round;stroke-linejoin:round;stroke-width:48px" stroke='currentColor'/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 924 B |
Reference in New Issue
Block a user