From 4e9c477bb358b9cbe89be646f32d0e51238e95f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=81=8F=E5=8F=B3?= Date: Sat, 17 Aug 2019 22:29:02 +0800 Subject: [PATCH] fix: Cascader notFoundContent width (#18325) * :bug: Fix Cascader notFoundContent width close #18176 * :lock: lock less to 3.9.0 https://github.com/less/less.js/issues/3416 https://github.com/less/less.js/issues/3414 --- .../__snapshots__/index.test.js.snap | 68 +++++++++++++++++++ components/cascader/__tests__/index.test.js | 12 ++++ components/cascader/index.tsx | 6 +- package.json | 1 + 4 files changed, 84 insertions(+), 3 deletions(-) diff --git a/components/cascader/__tests__/__snapshots__/index.test.js.snap b/components/cascader/__tests__/__snapshots__/index.test.js.snap index d6ecfaddafc6..c8d21910c6fa 100644 --- a/components/cascader/__tests__/__snapshots__/index.test.js.snap +++ b/components/cascader/__tests__/__snapshots__/index.test.js.snap @@ -349,6 +349,74 @@ exports[`Cascader can be selected 3`] = ` `; +exports[`Cascader have a notFoundContent that fit trigger input width 1`] = ` +
+
+
+
    + +
+
+
+
+`; + exports[`Cascader popup correctly when panel is hidden 1`] = `
{ mount(); }).not.toThrow(); }); + + // https://github.com/ant-design/ant-design/issues/18176 + it('have a notFoundContent that fit trigger input width', () => { + const wrapper = mount(); + const popupWrapper = mount( + wrapper + .find('Trigger') + .instance() + .getComponent(), + ); + expect(popupWrapper.render()).toMatchSnapshot(); + }); }); diff --git a/components/cascader/index.tsx b/components/cascader/index.tsx index 9f0222acdf56..87b48ba24bb6 100644 --- a/components/cascader/index.tsx +++ b/components/cascader/index.tsx @@ -496,12 +496,12 @@ class Cascader extends React.Component { ]); let { options } = props; + const names: FilledFieldNamesType = getFilledFieldNames(this.props); if (options && options.length > 0) { if (state.inputValue) { options = this.generateFilteredOptions(prefixCls, renderEmpty); } } else { - const names: FilledFieldNamesType = getFilledFieldNames(this.props); options = [ { [names.label]: notFoundContent || renderEmpty('Cascader'), @@ -519,7 +519,7 @@ class Cascader extends React.Component { const dropdownMenuColumnStyle: { width?: number; height?: string } = {}; const isNotFound = - (options || []).length === 1 && options[0].value === 'ANT_CASCADER_NOT_FOUND'; + (options || []).length === 1 && options[0][names.value] === 'ANT_CASCADER_NOT_FOUND'; if (isNotFound) { dropdownMenuColumnStyle.height = 'auto'; // Height of one row. } @@ -554,7 +554,7 @@ class Cascader extends React.Component { value={state.inputValue} disabled={disabled} readOnly={!showSearch} - autoComplete={inputProps.autoComplete || "off"} + autoComplete={inputProps.autoComplete || 'off'} onClick={showSearch ? this.handleInputClick : undefined} onBlur={showSearch ? this.handleInputBlur : undefined} onKeyDown={this.handleKeyDown} diff --git a/package.json b/package.json index 6dee06ae4f49..b0cfa124872f 100644 --- a/package.json +++ b/package.json @@ -144,6 +144,7 @@ "jest": "^24.8.0", "jsdom": "^15.1.1", "jsonml.js": "^0.1.0", + "less": "~3.9.0", "logrocket": "^1.0.0", "logrocket-react": "^3.0.0", "lz-string": "^1.4.4",