Skip to content

Commit 389552d

Browse files
authored
Merge pull request #4233 from Sage/FE-4218-prevent-focus-when-tile-select-disabled
fix(tile-select): prevent focus outline when tile select is disabled
2 parents 63707bc + 034107a commit 389552d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/components/tile-select/tile-select.component.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import PropTypes from "prop-types";
2-
import React, { useState } from "react";
2+
import React, { useState, useEffect } from "react";
33
import I18n from "i18n-js";
44
import styledSystemPropTypes from "@styled-system/prop-types";
55
import tagComponent from "../../utils/helpers/tags/tags";
@@ -68,6 +68,12 @@ const TileSelect = ({
6868
);
6969
};
7070

71+
useEffect(() => {
72+
if (disabled && hasFocus) {
73+
setHasFocus(false);
74+
}
75+
}, [disabled, hasFocus]);
76+
7177
return (
7278
<StyledTileSelectContainer
7379
checked={checked}

src/components/tile-select/tile-select.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,24 @@ describe("TileSelectGroup", () => {
381381
});
382382
});
383383

384+
describe("when input becomes disabled", () => {
385+
it("removes the focus outline", () => {
386+
wrapper = mount(<TileSelect />);
387+
388+
wrapper.find(StyledTileSelectInput).first().simulate("focus");
389+
expect(wrapper.find(StyledFocusWrapper).first().prop("hasFocus")).toEqual(
390+
true
391+
);
392+
393+
wrapper.setProps({ disabled: true });
394+
wrapper.update();
395+
396+
expect(wrapper.find(StyledFocusWrapper).first().prop("hasFocus")).toEqual(
397+
false
398+
);
399+
});
400+
});
401+
384402
describe("propTypes", () => {
385403
it("validates the incorrect children prop", () => {
386404
jest.spyOn(global.console, "error").mockImplementation(() => {});

0 commit comments

Comments
 (0)