Page MenuHomePhabricator

Lookup: Make sure the menu is closed if there are no menu items
Closed, ResolvedPublic1 Estimated Story PointsBUG REPORT

Description

In T350946, we added support for an initial list of menu items. However, there is one scenario that can result in an open menu with nothing to show:

  • Create a Lookup with an initial list of menu items but no "no results" content
  • Type in the Lookup until there are no results
  • Blur, then refocus
  • The menu will open but there will be nothing in it

Adding "no results" content fixes this, but the Lookup with initial suggestions should work with or without "no results" content. Instead, we should always check that there are either menu items or "no results" content before opening the menu.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
CCiufo-WMF changed the subtype of this task from "Task" to "Bug Report".

Change 1007947 had a related patch set uploaded (by LWatson; author: LWatson):

[design/codex@main] Lookup: menu is closed if there are no menu items

https://gerrit.wikimedia.org/r/1007947

Inside CodexExample, I created a LookupWithSuggestions in App.vue to check that the local changes in Codex fix the bug reported. The changes in Codex are in this patch. (Maybe there's an easier/faster way to check this without CodexExample.)

// App.vue
<template>
	<div>
		<p class="cdx-docs-demo-text">
			Selected value: {{ selection }}
		</p>

		<cdx-lookup
			v-model:selected="selection"
			:menu-items="menuItems"
			:menu-config="menuConfig"
			aria-label="Lookup with suggested items demo"
			@input="onInput"
		>
			<!-- <template #no-results>
				No results found.
			</template> -->
		</cdx-lookup>
	</div>
</template>

<script>
const { ref, defineComponent } = require( 'vue' );
// Codex is available from ResourceLoader at runtime and is available without needing a build step.
const { CdxLookup } = require( '../../codex.js' );
const vegetableItems = [
	{
		label: 'potato',
		description: 'root vegetable',
		value: 'Q10998'
	},
	{
		label: 'carrot',
		description: 'root vegetable, usually orange in color',
		value: 'Q81',
		tag: 'limited support'
	},
	{
		label: 'zucchini',
		description: 'Edible summer squash, typically green in colour',
		value: 'Q7533'
	},
	{
		label: 'eggplant',
		description: 'plant species Solanum melongena',
		value: 'Q7540'
	},
	{
		label: 'broccoli',
		description: 'edible green plant in the cabbage family',
		value: 'Q47722'
	},
	{
		label: 'cauliflower',
		description: 'vegetable, for the plant see Q7537 (Brassica oleracea var. botrytis)',
		value: 'Q23900272'
	},
	{
		label: 'brussels sprouts',
		description: 'vegetable',
		value: 'Q150463'
	},
	{
		label: 'cassava root',
		description: 'root vegetable',
		value: 'Q43304555'
	},
	{
		label: 'plantain',
		description: 'banana-like vegetable, less sweet',
		value: 'Q165449'
	},
	{
		label: 'cabbage',
		description: 'Vegetable, the generic term for several varieties.',
		value: 'Q14328596'
	},
	{
		label: 'napa cabbage',
		description: 'a type of Chinese cabbage',
		value: 'Q13360268'
	}
];

/**
 * Codex Vue component demos.
 *
 * This app contains a tabbed layout with various Codex Vue component demos. This component is
 * written using Vue's Composition API (see https://vuejs.org/api/composition-api-setup.html).
 */
// @vue/component
module.exports = defineComponent( {
	name: 'LookupWithSuggestions',
	components: {
		CdxLookup
	},
	setup() {

		const selection = ref( null );
		// Set up an array of initial menu items to show as suggestions.
		const initialMenuItems = [
			{
				label: 'Suggested items',
				value: 'suggestion',
				disabled: true
			},
			...vegetableItems.slice( 0, 3 )
		];
		const menuItems = ref( initialMenuItems );

		const menuConfig = {
			boldLabel: true
		};

		/**
		 * Filter items on input.
		 *
		 * @param {string} value
		 */
		function onInput( value ) {
			if ( value ) {
				menuItems.value = vegetableItems.filter( ( item ) =>
					item.label.includes( value )
				);
			} else {
				// When the input is cleared, show the suggestions again.
				menuItems.value = initialMenuItems;
			}
		}

		return {
			selection,
			menuItems,
			menuConfig,
			onInput
		};
	}
} );
</script>

<style lang="less">
// To access Codex design tokens and mixins inside Vue files, import MediaWiki skin variables.
@import 'mediawiki.skin.variables.less';

.ext-codexexample-app {
	&__tab {
		padding: @spacing-100;
	}
}
</style>
lwatson set the point value for this task to 1.Mar 1 2024, 6:06 PM

Change 1007947 merged by jenkins-bot:

[design/codex@main] Lookup: menu is closed if there are no menu items

https://gerrit.wikimedia.org/r/1007947

Change 1008950 had a related patch set uploaded (by LWatson; author: LWatson):

[mediawiki/core@master] Update Codex from v1.3.3 to v1.3.4

https://gerrit.wikimedia.org/r/1008950

Test wiki created on Patch demo by ATomasevich (WMF) using patch(es) linked to this task:
https://patchdemo.wmflabs.org/wikis/cd11cbf23a/w

Change 1008950 merged by jenkins-bot:

[mediawiki/core@master] Update Codex from v1.3.3 to v1.3.4

https://gerrit.wikimedia.org/r/1008950