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 Sep 8, 2023
1 parent 300a304 commit bfb86e2
Show file tree
Hide file tree
Showing 4 changed files with 70 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, And } from 'cypress-cucumber-preprocessor/steps'

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')
})

And('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 @@ -44,3 +44,41 @@ storiesOf('SingleSelectField', module)
))
.add('With loading', () => <SingleSelectField loading />)
.add('Without options', () => <SingleSelectField />)
.add('With hidden parent', () => {
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 bfb86e2

Please sign in to comment.