Combobox patch to prevent the suggestion list being left open after browser autocomplete (https://github.com/woocommerce/woocommerce-blocks/pull/4590)

* Combobox patch

* Update a package to invalidate CI cache

* Update cache handling

* revert eslint package change
This commit is contained in:
Mike Jolley 2021-08-17 13:25:11 +01:00 committed by GitHub
parent 71851f25a5
commit 717465ed99
5 changed files with 359 additions and 356 deletions

View File

@ -1,79 +1,76 @@
name: JavaScript and CSS Linting
on:
pull_request:
push:
branches: [trunk]
pull_request:
push:
branches: [trunk]
jobs:
Setup:
name: Setup for Jobs
runs-on: ubuntu-latest
Setup:
name: Setup for Jobs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-${{ env.cache-name }}-
${{ runner.OS }}-build-
${{ runner.OS }}-
- name: Install Node Dependencies
run: npm install
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-
- name: Install Node Dependencies
run: npm install
JSLintingCheck:
name: Lint JavaScript
needs: Setup
runs-on: ubuntu-latest
JSLintingCheck:
name: Lint JavaScript
needs: Setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-${{ env.cache-name }}-
${{ runner.OS }}-build-
${{ runner.OS }}-
- name: Install Node Dependencies
run: npm install
- name: Save Code Linting Report JSON
run: npm run lint:js:report
# Continue to the next step even if this fails
continue-on-error: true
- name: Upload ESLint report
uses: actions/upload-artifact@v2
with:
name: eslint_report.json
path: eslint_report.json
- name: Annotate Code Linting Results
uses: ataylorme/eslint-annotate-action@1.2.0
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
report-json: "eslint_report.json"
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-
- name: Install Node Dependencies
run: npm install
- name: Save Code Linting Report JSON
run: npm run lint:js:report
# Continue to the next step even if this fails
continue-on-error: true
- name: Upload ESLint report
uses: actions/upload-artifact@v2
with:
name: eslint_report.json
path: eslint_report.json
- name: Annotate Code Linting Results
uses: ataylorme/eslint-annotate-action@1.2.0
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
report-json: 'eslint_report.json'
CSSLintingCheck:
name: Lint CSS
needs: Setup
runs-on: ubuntu-latest
CSSLintingCheck:
name: Lint CSS
needs: Setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-${{ env.cache-name }}-
${{ runner.OS }}-build-
${{ runner.OS }}-
- name: Install Node Dependencies
run: npm install
- name: Lint CSS
run: npm run lint:css
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-
- name: Install Node Dependencies
run: npm install
- name: Lint CSS
run: npm run lint:css

View File

@ -1,188 +1,184 @@
name: E2E tests
on:
push:
branches: [trunk]
pull_request:
push:
branches: [trunk]
pull_request:
jobs:
Setup:
runs-on: ubuntu-latest
name: Setup
steps:
- uses: actions/checkout@v2
Setup:
runs-on: ubuntu-latest
name: Setup
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Npm install and build
run: |
npm ci
FORCE_REDUCED_MOTION=true npm run build:e2e-test
- name: Npm install and build
run: |
npm ci
FORCE_REDUCED_MOTION=true npm run build:e2e-test
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
tools: composer
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
tools: composer
- name: Composer install
run: |
composer install
- name: Composer install
run: |
composer install
JSE2EWithGutenberg:
name: JavaScript E2E Tests (WP latest with Gutenberg plugin)
needs: Setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
JSE2EWithGutenberg:
name: JavaScript E2E Tests (WP latest with Gutenberg plugin)
needs: Setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Npm install and build
run: |
npm ci
FORCE_REDUCED_MOTION=true npm run build:e2e-test
- name: Npm install and build
run: |
npm ci
FORCE_REDUCED_MOTION=true npm run build:e2e-test
- name: blocks.ini setup
run: |
echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = tests' > blocks.ini
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: blocks.ini setup
run: |
echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = tests' > blocks.ini
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
tools: composer
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
tools: composer
- name: Composer install
run: |
composer install
- name: Composer install
run: |
composer install
- name: E2E Tests (WP latest with Gutenberg plugin)
env:
WOOCOMMERCE_BLOCKS_PHASE: 3
run: |
chmod -R 767 ./ #needed for permissions issues
JSON='{"plugins": ["https://downloads.wordpress.org/plugin/woocommerce.latest-stable.zip","https://github.com/WP-API/Basic-Auth/archive/master.zip","https://downloads.wordpress.org/plugin/gutenberg.latest-stable.zip", "."] }'
echo $JSON > .wp-env.override.json
npm run wp-env start
npm run wp-env clean all
npm run test:e2e
- name: E2E Tests (WP latest with Gutenberg plugin)
env:
WOOCOMMERCE_BLOCKS_PHASE: 3
run: |
chmod -R 767 ./ #needed for permissions issues
JSON='{"plugins": ["https://downloads.wordpress.org/plugin/woocommerce.latest-stable.zip","https://github.com/WP-API/Basic-Auth/archive/master.zip","https://downloads.wordpress.org/plugin/gutenberg.latest-stable.zip", "."] }'
echo $JSON > .wp-env.override.json
npm run wp-env start
npm run wp-env clean all
npm run test:e2e
JSE2ETests:
name: JavaScript E2E Tests (latest)
needs: Setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
JSE2ETests:
name: JavaScript E2E Tests (latest)
needs: Setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Npm install and build
run: |
npm ci
FORCE_REDUCED_MOTION=true npm run build:e2e-test
- name: Npm install and build
run: |
npm ci
FORCE_REDUCED_MOTION=true npm run build:e2e-test
- name: blocks.ini setup
run: |
echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = tests' > blocks.ini
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: blocks.ini setup
run: |
echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = tests' > blocks.ini
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
tools: composer
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
tools: composer
- name: Composer install
run: |
composer install
- name: Composer install
run: |
composer install
- name: E2E Tests (WP latest)
env:
WOOCOMMERCE_BLOCKS_PHASE: 3
run: |
npm run wp-env start
npm run wp-env clean all
npm run test:e2e
- name: E2E Tests (WP latest)
env:
WOOCOMMERCE_BLOCKS_PHASE: 3
run: |
npm run wp-env start
npm run wp-env clean all
npm run test:e2e

View File

@ -1,138 +1,135 @@
name: Unit tests
on:
push:
branches: [trunk]
pull_request:
push:
branches: [trunk]
pull_request:
jobs:
Setup:
runs-on: ubuntu-latest
name: Setup
steps:
- uses: actions/checkout@v2
Setup:
runs-on: ubuntu-latest
name: Setup
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Npm install and build
run: |
npm ci
FORCE_REDUCED_MOTION=true npm run build:e2e-test
- name: Npm install and build
run: |
npm ci
FORCE_REDUCED_MOTION=true npm run build:e2e-test
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
tools: composer
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
tools: composer
- name: Composer install
run: |
composer install
- name: Composer install
run: |
composer install
PHPUnitTests:
name: PHP Unit Tests
needs: Setup
PHPUnitTests:
name: PHP Unit Tests
needs: Setup
runs-on: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
steps:
- uses: actions/checkout@v2
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
tools: composer
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
tools: composer
- name: Composer install
run: |
composer install
- name: Composer install
run: |
composer install
- name: blocks.ini setup
run: |
echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = tests' > blocks.ini
- name: blocks.ini setup
run: |
echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = tests' > blocks.ini
- name: Run PHP Unit tests
run: |
npm run phpunit
- name: Run PHP Unit tests
run: |
npm run phpunit
JSUnitTests:
name: JS Unit Tests
needs: Setup
JSUnitTests:
name: JS Unit Tests
needs: Setup
runs-on: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-
${{ runner.OS }}-build-${{ secrets.CACHE_VERSION }}-
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Npm install and build
run: |
npm ci
FORCE_REDUCED_MOTION=true npm run build:e2e-test
- name: Npm install and build
run: |
npm ci
FORCE_REDUCED_MOTION=true npm run build:e2e-test
- name: blocks.ini setup
run: |
echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = tests' > blocks.ini
- name: blocks.ini setup
run: |
echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = tests' > blocks.ini
- name: Run JavaScript Unit tests
run: |
npm run test
- name: Run JavaScript Unit tests
run: |
npm run test

View File

@ -94,6 +94,7 @@ const Combobox = ( {
] );
// @todo Remove patch for ComboboxControl once https://github.com/WordPress/gutenberg/pull/33928 is released
// Also see https://github.com/WordPress/gutenberg/pull/34090
return (
<div
id={ controlId }

View File

@ -1,5 +1,5 @@
diff --git a/node_modules/wordpress-components/build-module/combobox-control/index.js b/node_modules/wordpress-components/build-module/combobox-control/index.js
index 51c59c1..61bda14 100644
index 51c59c1..a4b58ab 100644
--- a/node_modules/wordpress-components/build-module/combobox-control/index.js
+++ b/node_modules/wordpress-components/build-module/combobox-control/index.js
@@ -1,19 +1,10 @@
@ -23,7 +23,7 @@ index 51c59c1..61bda14 100644
/**
* WordPress dependencies
*/
@@ -34,77 +25,46 @@ import BaseControl from '../base-control';
@@ -34,77 +25,47 @@ import BaseControl from '../base-control';
import Button from '../button';
import { Flex, FlexBlock, FlexItem } from '../flex';
import withFocusOutside from '../higher-order/with-focus-outside';
@ -125,6 +125,7 @@ index 51c59c1..61bda14 100644
+ const instanceId = useInstanceId(ComboboxControl);
+ const [selectedSuggestion, setSelectedSuggestion] = useState(currentOption || null);
+ const [isExpanded, setIsExpanded] = useState(false);
+ const [inputHasFocus, setInputHasFocus] = useState(false);
+ const [inputValue, setInputValue] = useState('');
+ const inputContainer = useRef();
+ const matchingSuggestions = useMemo(() => {
@ -136,7 +137,7 @@ index 51c59c1..61bda14 100644
if (index === 0) {
startsWithMatch.push(option);
@@ -115,7 +75,7 @@ function ComboboxControl(_ref) {
@@ -115,7 +76,7 @@ function ComboboxControl(_ref) {
return startsWithMatch.concat(containsMatch);
}, [inputValue, options, value]);
@ -145,7 +146,7 @@ index 51c59c1..61bda14 100644
onChange(newSelectedSuggestion.value);
speak(messages.selected, 'assertive');
setSelectedSuggestion(newSelectedSuggestion);
@@ -123,10 +83,9 @@ function ComboboxControl(_ref) {
@@ -123,10 +84,9 @@ function ComboboxControl(_ref) {
setIsExpanded(false);
};
@ -159,7 +160,7 @@ index 51c59c1..61bda14 100644
if (nextIndex < 0) {
nextIndex = matchingSuggestions.length - 1;
@@ -138,8 +97,12 @@ function ComboboxControl(_ref) {
@@ -138,8 +98,12 @@ function ComboboxControl(_ref) {
setIsExpanded(true);
};
@ -174,7 +175,7 @@ index 51c59c1..61bda14 100644
switch (event.keyCode) {
case ENTER:
@@ -164,7 +127,6 @@ function ComboboxControl(_ref) {
@@ -164,7 +128,6 @@ function ComboboxControl(_ref) {
setIsExpanded(false);
setSelectedSuggestion(null);
preventDefault = true;
@ -182,12 +183,17 @@ index 51c59c1..61bda14 100644
break;
default:
@@ -176,34 +138,44 @@ function ComboboxControl(_ref) {
@@ -176,34 +139,52 @@ function ComboboxControl(_ref) {
}
};
- var onFocus = function onFocus() {
+ const onBlur = () => {
+ setInputHasFocus(false);
+ };
+
+ const onFocus = () => {
+ setInputHasFocus(true);
setIsExpanded(true);
onFilterValueChange('');
setInputValue('');
@ -204,7 +210,11 @@ index 51c59c1..61bda14 100644
+ const text = event.value;
setInputValue(text);
onFilterValueChange(text);
setIsExpanded(true);
- setIsExpanded(true);
+
+ if (inputHasFocus) {
+ setIsExpanded(true);
+ }
};
- var handleOnReset = function handleOnReset() {
@ -213,14 +223,14 @@ index 51c59c1..61bda14 100644
inputContainer.current.input.focus();
- }; // Announcements
+ }; // Update current selections when the filter input changes.
+
- useEffect(function () {
- var hasMatchingSuggestions = matchingSuggestions.length > 0;
+ useEffect(() => {
+ const hasMatchingSuggestions = matchingSuggestions.length > 0;
+ const hasSelectedMatchingSuggestions = matchingSuggestions.indexOf(selectedSuggestion) > 0;
+
- useEffect(function () {
- var hasMatchingSuggestions = matchingSuggestions.length > 0;
+ if (hasMatchingSuggestions && !hasSelectedMatchingSuggestions) {
+ // If the current selection isn't present in the list of suggestions, then automatically select the first item from the list of suggestions.
+ setSelectedSuggestion(matchingSuggestions[0]);
@ -236,7 +246,7 @@ index 51c59c1..61bda14 100644
/* translators: %d: number of results. */
_n('%d result found, use up and down arrow keys to navigate.', '%d results found, use up and down arrow keys to navigate.', matchingSuggestions.length), matchingSuggestions.length) : __('No results.');
speak(message, 'polite');
@@ -220,7 +192,7 @@ function ComboboxControl(_ref) {
@@ -220,7 +201,7 @@ function ComboboxControl(_ref) {
className: classnames(className, 'components-combobox-control'),
tabIndex: "-1",
label: label,
@ -245,16 +255,18 @@ index 51c59c1..61bda14 100644
hideLabelFromVision: hideLabelFromVision,
help: help
}, createElement("div", {
@@ -232,7 +204,7 @@ function ComboboxControl(_ref) {
@@ -232,8 +213,9 @@ function ComboboxControl(_ref) {
instanceId: instanceId,
ref: inputContainer,
value: isExpanded ? inputValue : currentLabel,
- "aria-label": currentLabel ? "".concat(currentLabel, ", ").concat(label) : null,
+ "aria-label": currentLabel ? `${currentLabel}, ${label}` : null,
onFocus: onFocus,
+ onBlur: onBlur,
isExpanded: isExpanded,
selectedSuggestionIndex: matchingSuggestions.indexOf(selectedSuggestion),
@@ -248,9 +220,7 @@ function ComboboxControl(_ref) {
onChange: onInputChange
@@ -248,9 +230,7 @@ function ComboboxControl(_ref) {
match: {
label: inputValue
},