-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Menu, Popover, Select] Add
data-pressed
to MenuTrigger, PopoverTri…
…gger and SelectTrigger (#826)
- Loading branch information
1 parent
d7089ab
commit c39d873
Showing
11 changed files
with
182 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/mui-base/src/Select/Trigger/SelectTrigger.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as React from 'react'; | ||
import { Select } from '@base_ui/react/Select'; | ||
import { createRenderer, describeConformance } from '#test-utils'; | ||
import { expect } from 'chai'; | ||
import { act, screen } from '@mui/internal-test-utils'; | ||
|
||
describe('<Select.Trigger />', () => { | ||
const { render } = createRenderer(); | ||
|
||
describeConformance(<Select.Trigger />, () => ({ | ||
refInstanceof: window.HTMLDivElement, | ||
render(node) { | ||
return render( | ||
<Select.Root open animated={false}> | ||
{node} | ||
</Select.Root>, | ||
); | ||
}, | ||
})); | ||
|
||
describe('style hooks', () => { | ||
it('should have the data-popup-open and data-pressed attributes when open', async () => { | ||
await render( | ||
<Select.Root animated={false}> | ||
<Select.Trigger /> | ||
</Select.Root>, | ||
); | ||
|
||
const trigger = screen.getByRole('combobox'); | ||
|
||
await act(async () => { | ||
trigger.click(); | ||
}); | ||
|
||
expect(trigger).to.have.attribute('data-popup-open'); | ||
expect(trigger).to.have.attribute('data-pressed'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,41 @@ | ||
import type { CustomStyleHookMapping } from './getStyleHookProps'; | ||
|
||
export const triggerOpenStateMapping: CustomStyleHookMapping<{ open: boolean }> = { | ||
const TRIGGER_HOOK = { | ||
'data-popup-open': '', | ||
}; | ||
|
||
const PRESSABLE_TRIGGER_HOOK = { | ||
'data-popup-open': '', | ||
'data-pressed': '', | ||
}; | ||
|
||
const POPUP_HOOK = { | ||
'data-open': '', | ||
}; | ||
|
||
export const triggerOpenStateMapping = { | ||
open(value) { | ||
if (value) { | ||
return { | ||
'data-popup-open': '', | ||
}; | ||
return TRIGGER_HOOK; | ||
} | ||
return null; | ||
}, | ||
}; | ||
} satisfies CustomStyleHookMapping<{ open: boolean }>; | ||
|
||
export const popupOpenStateMapping: CustomStyleHookMapping<{ open: boolean }> = { | ||
export const pressableTriggerOpenStateMapping = { | ||
open(value) { | ||
if (value) { | ||
return { | ||
'data-open': '', | ||
}; | ||
return PRESSABLE_TRIGGER_HOOK; | ||
} | ||
return null; | ||
}, | ||
}; | ||
} satisfies CustomStyleHookMapping<{ open: boolean }>; | ||
|
||
export const popupOpenStateMapping = { | ||
open(value) { | ||
if (value) { | ||
return POPUP_HOOK; | ||
} | ||
return null; | ||
}, | ||
} satisfies CustomStyleHookMapping<{ open: boolean }>; |