Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ const onChange = (e: Readonly<Event>): void => {
}

const onKeydown = (e: Readonly<KeyboardEvent>): void => {
if (e.key === 'Enter' && !props.noAddOnEnter) {
if ((e.key === 'Enter' || e.code === 'NumpadEnter') && !props.noAddOnEnter) {
addTag(inputValue.value)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ const handleHeaderKeydown = (field: TableField<Items>, event: KeyboardEvent, isF

if (target && (target as Element).tagName !== 'TH' && document.activeElement === target) return

if (code === 'Enter' || code === 'Space') {
if (code === 'Enter' || code === 'NumpadEnter' || code === 'Space') {
stopEvent(event)
headerClicked(field, event as unknown as MouseEvent, isFooter)
}
Expand All @@ -485,7 +485,7 @@ const handleRowKeydown = (item: Items, itemIndex: number, event: KeyboardEvent)

if (target && (target as Element).tagName !== 'TR' && document.activeElement === target) return

if (code === 'Enter' || code === 'Space') {
if (code === 'Enter' || code === 'NumpadEnter' || code === 'Space') {
stopEvent(event)
emit('row-clicked', item, itemIndex, event as unknown as MouseEvent)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ describe('BTable keyboard navigation', () => {
expect(nameHeader.attributes('aria-sort')).toBe('ascending')
})

it('should trigger sort when NumpadEnter key is pressed on header', async () => {
const wrapper = mount(BTable, {
props: {
items: testItems,
fields: testFields,
},
})

const nameHeader = wrapper.find('th[tabindex="0"]')

// Simulate NumpadEnter key press
await nameHeader.trigger('keydown', {code: 'NumpadEnter'})

// Check that sort was applied (aria-sort should change)
await nextTick()
expect(nameHeader.attributes('aria-sort')).toBe('ascending')
})

it('should trigger sort when Space key is pressed on header', async () => {
const wrapper = mount(BTable, {
props: {
Expand Down Expand Up @@ -141,6 +159,25 @@ describe('BTable keyboard navigation', () => {
expect(wrapper.emitted('row-clicked')![0][0]).toEqual(testItems[0])
})

it('should trigger row click when NumpadEnter key is pressed', async () => {
const wrapper = mount(BTable, {
props: {
items: testItems,
fields: testFields,
selectable: true,
},
})

const firstRow = wrapper.find('tbody tr[tabindex="0"]')

// Simulate NumpadEnter key press
await firstRow.trigger('keydown', {code: 'NumpadEnter'})

// Check that row-clicked event was emitted
expect(wrapper.emitted('row-clicked')).toBeTruthy()
expect(wrapper.emitted('row-clicked')![0][0]).toEqual(testItems[0])
})

it('should trigger row click when Space key is pressed', async () => {
const wrapper = mount(BTable, {
props: {
Expand Down Expand Up @@ -207,6 +244,27 @@ describe('BTable keyboard navigation', () => {
expect(firstRow.classes()).toContain('selected')
})

it('should work with selection mode using NumpadEnter', async () => {
const wrapper = mount(BTable, {
props: {
'items': testItems,
'fields': testFields,
'selectable': true,
'selectedItems': [],
'onUpdate:selectedItems': (value) => wrapper.setProps({selectedItems: value}),
},
})

const firstRow = wrapper.find('tbody tr[tabindex="0"]')

// Simulate NumpadEnter key press to select row
await firstRow.trigger('keydown', {code: 'NumpadEnter'})
await nextTick()

// Row should be selected (have the selected class)
expect(firstRow.classes()).toContain('selected')
})

it('should work with sorting', async () => {
const wrapper = mount(BTable, {
props: {
Expand All @@ -228,5 +286,27 @@ describe('BTable keyboard navigation', () => {
// After sorting by name ascending, Bob Johnson should be first
expect(firstRowData[0].text()).toBe('Bob Johnson')
})

it('should work with sorting using NumpadEnter', async () => {
const wrapper = mount(BTable, {
props: {
items: testItems,
fields: testFields,
},
})

const nameHeader = wrapper.find('th[tabindex="0"]')

// Sort using keyboard with NumpadEnter
await nameHeader.trigger('keydown', {code: 'NumpadEnter'})
await nextTick()

// Check that table data is sorted
const rows = wrapper.findAll('tbody tr')
const firstRowData = rows[0].findAll('td')

// After sorting by name ascending, Bob Johnson should be first
expect(firstRowData[0].text()).toBe('Bob Johnson')
})
})
})
Loading