mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 11:28:24 +00:00 
			
		
		
		
	Correctly query the primary button in a form (#32438)
The "primary button" is used at many places, but sometimes they might conflict (due to button switch, hidden panel, dropdown menu, etc). Sometimes we could add a special CSS class for the buttons, but sometimes not (see the comment of QuickSubmit) This PR introduces `querySingleVisibleElem` to help to get the correct primary button (the only visible one), and prevent from querying the wrong buttons. Fix #32437 --------- Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
		| @@ -1,3 +1,5 @@ | ||||
| import {querySingleVisibleElem} from '../../utils/dom.ts'; | ||||
|  | ||||
| export function handleGlobalEnterQuickSubmit(target) { | ||||
|   let form = target.closest('form'); | ||||
|   if (form) { | ||||
| @@ -12,7 +14,11 @@ export function handleGlobalEnterQuickSubmit(target) { | ||||
|   } | ||||
|   form = target.closest('.ui.form'); | ||||
|   if (form) { | ||||
|     form.querySelector('.ui.primary.button')?.click(); | ||||
|     // A form should only have at most one "primary" button to do quick-submit. | ||||
|     // Here we don't use a special class to mark the primary button, | ||||
|     // because there could be a lot of forms with a primary button, the quick submit should work out-of-box, | ||||
|     // but not keeps asking developers to add that special class again and again (it could be forgotten easily) | ||||
|     querySingleVisibleElem<HTMLButtonElement>(form, '.ui.primary.button')?.click(); | ||||
|     return true; | ||||
|   } | ||||
|   return false; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user