Skip to content

Commit 317c8a8

Browse files
Fix the input styles when using a Bootstrap (GH-44)
2 parents f8c826c + 86f476b commit 317c8a8

File tree

6 files changed

+33
-7
lines changed

6 files changed

+33
-7
lines changed

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
examples
2+
scripts
3+
tests

examples/antd5.x/src/Demo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const Demo = () => {
3434
<ConfigProvider
3535
theme={{algorithm: algorithm === "defaultAlgorithm" ? theme.defaultAlgorithm : theme.darkAlgorithm}}>
3636
<Card style={{height: "100%", borderRadius: 0, border: "none"}} bodyStyle={{padding: 0}}>
37-
<div className="m-5" style={{margin: 20, maxWidth: 400}}>
37+
<div style={{margin: 20, maxWidth: 400}}>
3838
{value && (
3939
<pre style={{
4040
background: algorithm === "defaultAlgorithm" ? "#efefef" : "#1f1f1f",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.2.0",
2+
"version": "0.2.1",
33
"name": "antd-phone-input",
44
"description": "Advanced, highly customizable phone input component for Ant Design.",
55
"keywords": [

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const PhoneInput = (inputLegacyProps: PhoneInputProps) => {
1616
const dropdownPrefixCls = getPrefixCls("dropdown");
1717
const [_1, inputCls] = genComponentStyleHook(inputPrefixCls);
1818
const [_2, dropdownCls] = genComponentStyleHook(dropdownPrefixCls);
19-
const [theme, token, _3] = useToken();
19+
const [theme, token] = useToken();
2020

2121
const inputClass = useMemo(() => {
2222
return `${inputCls} ` + getStatusClassNames(inputPrefixCls, status);

src/legacy/style.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
export default (cssText: string) => {
2+
window.addEventListener("load", () => {
3+
/** Resolve the overlap issue of the CSS rules when using Bootstrap */
4+
for (const styleSheet of Array.from(document.styleSheets)) {
5+
try {
6+
for (const rule of Array.from(styleSheet.cssRules || styleSheet.rules)) {
7+
if (rule instanceof CSSStyleRule) {
8+
rule.selectorText = rule.selectorText.replace(
9+
/^\.form-control(?=:|$)/,
10+
".form-control:not(.ant-input)",
11+
)
12+
}
13+
}
14+
} catch (e) {
15+
}
16+
}
17+
})
18+
19+
/** Inject the given `cssText` in the document head */
220
const style = document.createElement("style");
321
style.setAttribute("type", "text/css");
422

src/style.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
import {GlobalToken} from "antd/lib/theme/interface";
2-
import {genBasicInputStyle, initInputToken} from "antd/lib/input/style";
1+
import {mergeToken} from "antd/lib/theme/internal";
2+
import * as inputHelper from "antd/lib/input/style";
33

4-
export default (token: GlobalToken) => ({
4+
export default (token: any) => ({
55
".react-tel-input": {
66
".country-list": {
77
boxShadow: token.boxShadow,
88
backgroundColor: token.colorBgElevated,
99
".country-name": {color: token.colorText},
1010
".search": {backgroundColor: token.colorBgElevated},
11-
".search-box": genBasicInputStyle(initInputToken(token) as any),
11+
".search-box": inputHelper.genBasicInputStyle(
12+
mergeToken(
13+
((inputHelper as any).initInputToken || (() => ({})))(token),
14+
((inputHelper as any).initComponentToken || (() => ({})))(token),
15+
)
16+
),
1217
".country": {
1318
borderRadius: token.borderRadiusOuter,
1419
".dial-code": {color: token.colorTextDescription},

0 commit comments

Comments
 (0)