Skip to content
This repository was archived by the owner on Mar 21, 2019. It is now read-only.

Adding focusable to generated <svg> tag based on props #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ test("SVGInline: should add height", t => {
t.is(result, `${SVGInlineStart} style="height: 1rem;"><g></g></svg></span>`);
});

test("SVGInline: should add focusable", t => {
const result = ReactDOMServer.renderToStaticMarkup(
<SVGInline svg={"<svg><g></g></svg>"} focusable="false" />
);
t.is(result, `${SVGInlineStart} focusable="false"><g></g></svg></span>`);
});

test("SVGInline: does not pass internal props to component", t => {
const TestComponent = props => {
t.not(props.className, undefined);
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class SVGInline extends Component {
svg,
fill,
width,
focusable,
accessibilityLabel,
accessibilityDesc,
classSuffix,
Expand Down Expand Up @@ -78,7 +79,8 @@ class SVGInline extends Component {
(width ? `width: ${width};` : "") +
(height ? `height: ${height};` : "") +
'"'
: "")
: "") +
(focusable ? ` focusable="${focusable}"` : "")
);
let match;
if (accessibilityDesc) {
Expand Down Expand Up @@ -120,6 +122,7 @@ SVGInline.propTypes = {
cleanupExceptions: PropTypes.array,
width: PropTypes.string,
height: PropTypes.string,
focusable: PropTypes.string,
accessibilityLabel: PropTypes.string,
accessibilityDesc: PropTypes.string
};
Expand Down