selectWoo icon indicating copy to clipboard operation
selectWoo copied to clipboard

selectWoo / select2 dropdown positioned incorrectly when html has margin-top

Open douglas-johnson opened this issue 4 years ago • 3 comments

Prerequisites (mark completed items with an [x]):

  • [x] I have have carried out troubleshooting steps and I believe I have found a bug.
  • [x] I have searched for similar bugs in both open and closed issues and cannot find a duplicate.

Describe the bug When the admin-bar is displayed on the front-end of WordPress, the html element has margin-top, and the select2 dropdown is positioned incorrectly.

I think this is caused by the use of the jQuery function .offset() which does not include the html element's margin. This is noted in the jQuery documentation: https://api.jquery.com/offset/

jQuery does not support getting the offset coordinates of hidden elements or accounting for margins set on the <html> document element.

Expected behavior I expect to see the current selection above the dropdown while the dropdown is open.

Actual behavior The current selection is covered by the dropdown only when the WordPress admin-bar is shown.

Steps to reproduce the bug (We need to be able to reproduce the bug in order to fix it.) Steps to reproduce the bug:

  1. Log in to WordPress / WooCommerce
  2. Try to add an address, either in Checkout or My Account.

Screenshots

Logged In

Screen Shot 2021-03-03 at 12 16 16 PM

Logged Out

Screen Shot 2021-03-03 at 12 16 57 PM

Isolating the problem (mark completed items with an [x]):

  • [x] I have deactivated other plugins and confirmed this bug occurs when only WooCommerce plugin is active.
  • [x] This bug happens with a default WordPress theme active, or Storefront.
  • [x] I can reproduce this bug consistently using the steps above.

Fixes I've Tried

I fixed this in my own theme styles by adding margin-top to .select2-dropdown that corresponds to the admin-bar height.

body.admin-bar .select2-dropdown {
  margin-top: 32px;
}
@media( max-width: 782px ) {
  body.admin-bar .select2-dropdown {
      margin-top: 46px;
  }
}

douglas-johnson avatar Mar 03 '21 18:03 douglas-johnson

We are also running into this and it broke our selectWoo usage as well. Seems new in a recent update: either WooCommerce or Wordpress 5.7, but I haven't confirmed exact one; just know that it broke recently.

broksonic21 avatar Mar 18 '21 21:03 broksonic21

This was addressed in https://github.com/woocommerce/woocommerce/pull/29397 but not here in the selectWoo repo

douglas-johnson avatar Apr 19 '21 13:04 douglas-johnson

I have come across the same issue on some pages in WordPress v6.0.1 and WooCommerce 6.8.0. There is no longer "admin-bar" class added to BODY when the admin bar appears, so the above styles don't help! select2.full.js?ver=4.0.3-wc.6.8.0 does NOT contain the attachBody fixes from https://github.com/woocommerce/selectWoo/pull/49/files Applying these 2 changes fixes the issue.

PhilMakower avatar Aug 12 '22 09:08 PhilMakower