Skip to content

Commit

Permalink
fix: select-field not showing in correct place
Browse files Browse the repository at this point in the history
  • Loading branch information
kabaros committed Aug 12, 2024
1 parent e8b0559 commit 7d27d71
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/select/src/select/menu-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const MenuWrapper = ({
selectRef,
}) => {
return (
<Layer onBackdropClick={onClick} transparent>
<Layer onBackdropClick={onClick} transparent disablePortal>
<Popper
reference={selectRef}
placement="bottom-start"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Position of SelectField

Scenario: Keeps position when parent is hidden initially
Given a Select is hidden initially
When someone hovers over it to show it
And clicks the select
Then the select dropdown should be in the correct position
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Given, Then, When } from '@badeball/cypress-cucumber-preprocessor'

Given('a Select is hidden initially', () => {
cy.visitStory('SingleSelectField', 'With hidden parent')
})

When('someone hovers over it to show it', () => {
cy.get('.container .hiddenSelect').invoke('attr', 'style', 'display: block')
})

When('clicks the select', () => {
cy.get('[data-test="dhis2-uicore-select"]').click()
})

Then('the select dropdown should be in the correct position', () => {
cy.get('[data-test="hoverable-select-field"]').should('be.visible')
cy.get('[data-test="dhis2-uicore-singleselectoption"]').should(
($selectField) => {
const { top, left } = $selectField.offset()
expect(top).to.be.greaterThan(0)
expect(left).to.be.greaterThan(0)
}
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,42 @@ export const WithFilterable = () => (
)
export const WithLoading = () => <SingleSelectField loading />
export const WithoutOptions = () => <SingleSelectField />

export const WithHiddenParent = () => {
return (
<>
<div className="container">
<div className="hoverSpan">
<span>Hover over me</span>
<div className="hiddenSelect">
<SingleSelectField
dataTest="hoverable-select-field"
label="Choose something"
onChange={() => {}}
>
<SingleSelectOption value="1" label="one" />
<SingleSelectOption value="2" label="two" />
</SingleSelectField>
</div>
</div>
</div>
<style jsx>{`
.container {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 1rem;
}
.hiddenSelect {
display: none;
}
.hoverSpan:hover .hiddenSelect {
display: block;
}
`}</style>
</>
)
}

0 comments on commit 7d27d71

Please sign in to comment.